A list of XPath wildcards which are used with the XPath expressions.
Index | Wildcard | Expression |
---|---|---|
1) | * | It is used to match any node. |
2) | . | It is used to match the current node in context. |
3) | @* | It is used to match any attribute. |
4) | node() | It is used to match node of any type. |
Let's take an example to create a table of <employee> element with their detail, by iterating over each employee.
Employee.xml
<?xml version = "1.0"?> <?xml-stylesheet type = "text/xsl" href = "employee.xsl"?> <class> <employee id = "001"> <firstname>Abhiram</firstname> <lastname>Kushwaha</lastname> <nickname>Manoj</nickname> <salary>15000</salary> </employee> <employee id = "002"> <firstname>Akash</firstname> <lastname>Singh</lastname> <nickname>Bunty</nickname> <salary>25000</salary> </employee> <employee id = "003"> <firstname>Brijesh</firstname> <lastname>Kaushik</lastname> <nickname>Ballu</nickname> <salary>20000</salary> </employee> <employee id = "004"> <firstname>Zoya</firstname> <lastname>Mansoori</lastname> <nickname>Sonam</nickname> <salary>30000</salary> </employee> </class>
Employee.xsl
<?xml version = "1.0" encoding = "UTF-8"?> <xsl:stylesheet version = "1.0"> xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"> <xsl:template match = "/"> <html> <body> <h2>Employee </h2> <xsl:apply-templates select = "class/*" /> </body> </html> </xsl:template> <xsl:template match = "class/*"> <xsl:apply-templates select = "@id" /> <xsl:apply-templates select = "firstname" /> <xsl:apply-templates select = "lastname" /> <xsl:apply-templates select = "nickname" /> <xsl:apply-templates select = "salary" /> <br /> </xsl:template> <xsl:template match = "@id"> <span style = "font-size = 22px;"> <xsl:value-of select = "." /> </span> <br /> </xsl:template> <xsl:template match = "firstname"> First Name: <span style = "color:blue;"> <xsl:value-of select = "." /> </span> <br /> </xsl:template> <xsl:template match = "lastname"> Last Name: <span style = "color:green;"> <xsl:value-of select = "." /> </span> <br /> </xsl:template> <xsl:template match = "nickname"> Nick Name: <span style = "color:red;"> <xsl:value-of select = "." /> </span> <br /> </xsl:template> <xsl:template match = "salary"> Salary: <span style = "color:brown;"> <xsl:value-of select = "." /> </span> <br /> </xsl:template> </xsl:stylesheet>
Output: