[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
How_To_XML_Display_Mixed_XML_XSLT
Create the XML document and link it to the XSL stylesheet.
Create the XSL stylesheet.
Output:
Attributes are referred to the same way as elements with the difference that attribute names are preceeded by the @ sign.
This creates a new template to process further elements that start from the element specified.
This matches all occurences of the specified element.
This outputs the text value of all <title> elements found.
This outputs the attribute's value.
XML FAQ
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
How_To_XML_Display_Mixed_XML_XSLT
How to display mixed XML content in HTML using ?XSLT?
XML content is mixed when text and attributes are both present inside an element. The <title> element has mixed content in the example: two attributes: ISBN and author, and the element's text: OpenGL Programming Guide Fourth Edition.Create the XML document and link it to the XSL stylesheet.
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="mixed.xsl"?> <books> <book> <title ISBN="0321173481" author="Michael R. Sweet"> OpenGL Programming Guide Fourth Edition</title> </book> <book> <title ISBN="0849371643" author="Gerald Farin"> Curves and Surfaces for CAGD: A Practical Guide</title> </book> <book> <title ISBN="1558606696" author="David Rogers"> An Introduction to NURBS: With Historical Perspective</title> </book> <book> <title ISBN="1568810849" author="Gerald Farin"> NURBS: From Projective Geometry to Practical Use</title> </book> </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="10%"><B>ISBN</B></TD>
<TD width="20%"><B>Author</B></TD>
<TD width="40%"><B>Title</B></TD>
</TR>
</THEAD>
<TBODY>
<xsl:for-each select="books/book">
<TR>
<xsl:apply-templates select="title" />
<TD width="40%"><xsl:value-of select="title" /></TD>
</TR>
</xsl:for-each>
</TBODY>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="title">
<TD width="10%"><xsl:value-of select="@ISBN" /></TD>
<TD width="20%"><xsl:value-of select="@author" /></TD>
</xsl:template>
</xsl:stylesheet>Output:
ISBN Author Title 0321173481 Michael R. Sweet OpenGL Programming Guide Fourth Edition 0849371643 Gerald Farin Curves and Surfaces for CAGD: A Practical Guide1558606696 David Rogers An Introduction to NURBS: With Historical Perspective 1568810849 Gerald Farin NURBS: From Projective Geometry to Practical Use
Attributes are referred to the same way as elements with the difference that attribute names are preceeded by the @ sign.
<xsl:apply-templates select="title" />
This creates a new template to process further elements that start from the element specified.
<xsl:template match="title">
This matches all occurences of the specified element.
<xsl:value-of select="title" />
This outputs the text value of all <title> elements found.
<xsl:value-of select="@ISBN" />
This outputs the attribute's value.
XML FAQ
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
