0
15kviews
What is XML, XPATH, XSL and XSLT? Explain with an example.
1 Answer
written 6.3 years ago by |
<?xml version="1.0" encoding="UTF-8"?> <bookstore> <book> <title>Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> </book> <book> <title>Internet Programming</title> <author>Binita Mayekar</author> <year>2018</year> </book> </bookstore>
<?xml-stylesheet type='text/xsl' href='style.xsl'?>
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="https://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <table border="1"> <tr style="background-color:lightblue;color:black"> <th align="center">Book Name</th> <th align="center">Author</th> <th align="center">Year</th> </tr> <xsl:for-each select="bookstore/book"> <tr><td><xsl:value-of select="title"/></td> <td><xsl:value-of select="author"/></td> <td><xsl:value-of select="year"/></td></tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
<xsl:value-of>
- Extracts the value of a selected node.<xsl:for-each>
- Select every XML element of a specified node-set.<xsl:if>
- Put a conditional if test against the content of the XML file.<xsl:sort>
- Sort the output.<xsl:choose>
- Used along with <xsl:when>
and <xsl:otherwise>
to express multiple conditional tests.<xsl:template>
- Defines a template.<xsl:apply-template>
- Applies a template to the current element or to the current element's child node.XSLT Working:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="https://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <table border="1"> <tr style="background-color:lightblue;color:black"> <th align="center">Book Name</th> <th align="center">Author</th> <th align="center">Year</th> </tr> <xsl:for-each select="bookstore/book"> <xsl:if test="year=2018"> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="author"/></td> <td><xsl:value-of select="year"/></td> </tr> </xsl:if> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
nodename
- Selects all nodes with the name "nodename"./
- Selects from the root node.//
- Selects nodes in the document from the current node that match the selection no matter where they are..
- Selects the current node...
- Selects the parent of the current node.@
- Selects attributes.|
operator in an XPath expression select several paths.