[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
How_To_XML_Display_XML_Attributes_XSLT
Attributes are referred to the same way as elements but the attribute's name is preceeded by the @ sign.
Create the XML document and link it to the XSL stylesheet.
Create the XSL stylesheet.
This looks for the root element <books> in this case, and start the tranformation from there.
This creates a row for each <book> element found inside <books>.
XML FAQ
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
How_To_XML_Display_XML_Attributes_XSLT
How to display XML attributes in HTML using XSLT?
The example XML document has one root element <books> and a number of child elements <book>. Each child element has two attributes ISBN and author.Attributes are referred to the same way as elements but the attribute's name is preceeded by the @ sign.
Create the XML document and link it to the XSL stylesheet.
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="books06.xsl"?> <books> <book ISBN="0321173481" author="Michael R. Sweet" /> <book ISBN="0849371643" author="Gerald Farin" /> <book ISBN="1558606696" author="David Rogers" /> <book ISBN="1568810849" author="Gerald Farin" /> </books>
Create the XSL stylesheet.
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" encoding="UTF-8"/> <xsl:template match="/"> <html> <head><title>Books</title> </head> <body> <table width="100%" border="1"> <THEAD> <TR> <TD width="50%"><B>ISBN</B></TD> <TD width="50%"><B>Author</B></TD> </TR> </THEAD> <TBODY> <xsl:for-each select="books/book"> <TR> <TD width="50%"><xsl:value-of select="@ISBN" /></TD> <TD width="50%"><xsl:value-of select="@author" /></TD> </TR> </xsl:for-each> </TBODY> </table> </body> </html> </xsl:template> </xsl:stylesheet>
<xsl:template match="/">
This looks for the root element <books> in this case, and start the tranformation from there.
<xsl:for-each select="books/book">
This creates a row for each <book> element found inside <books>.
<xsl:value-of select="@ISBN" /> <xsl:value-of select="@author" />This takes the ISBN and author attributes' values from the XML and display them as the contents of the table cells.
XML FAQ
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
