Generic XSLT
-
I need to create a generic XSLT to extract the third level elements of an XML file without having to specify the element names in the XPath. The XML file looks like that <?xml version="1.0" encoding="ISO-8859-1"?> <catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd> . . . </catalog> I need to put the Elements names like title, artist, etc. in a table as header and the element text Empire Burlesque, Bob Dylan in a table cell. Can someone assist me with this please it seems I cannot get it right myself. Here's what I am trying but doesn't work <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <!-- The heading --> <div> Results </div> <br/> <!-- Define the table itself --> <table width="100%" border="1"> xsl:apply-templates/ </table> </body> </html> </xsl:template> <xsl:template match="*"> <xsl:for-each select="*"> <xsl:sort select="*"/> <tr> <td><xsl:value-of select="*"/></td> </tr> </xsl:for-each> </xsl:template> </xsl:stylesheet> Thanks Tony
-
I need to create a generic XSLT to extract the third level elements of an XML file without having to specify the element names in the XPath. The XML file looks like that <?xml version="1.0" encoding="ISO-8859-1"?> <catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd> . . . </catalog> I need to put the Elements names like title, artist, etc. in a table as header and the element text Empire Burlesque, Bob Dylan in a table cell. Can someone assist me with this please it seems I cannot get it right myself. Here's what I am trying but doesn't work <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <!-- The heading --> <div> Results </div> <br/> <!-- Define the table itself --> <table width="100%" border="1"> xsl:apply-templates/ </table> </body> </html> </xsl:template> <xsl:template match="*"> <xsl:for-each select="*"> <xsl:sort select="*"/> <tr> <td><xsl:value-of select="*"/></td> </tr> </xsl:for-each> </xsl:template> </xsl:stylesheet> Thanks Tony
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> <xsl:template match="/"> <html> <body> <!-- The heading --> <div> Results </div> <br/> <!-- Define the table itself --> <table width="100%" border="1"> <tr> <xsl:for-each select="/*/* [position()=1] /*"> <th> <xsl:value-of select="name()"/> </th> </xsl:for-each> </tr> xsl:apply-templates/ </table> </body> </html> </xsl:template> <xsl:template match="/*/*"> <tr> <xsl:for-each select="*"> <td> <xsl:value-of select="."/> </td> </xsl:for-each> </tr> </xsl:template> </xsl:stylesheet>
-
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> <xsl:template match="/"> <html> <body> <!-- The heading --> <div> Results </div> <br/> <!-- Define the table itself --> <table width="100%" border="1"> <tr> <xsl:for-each select="/*/* [position()=1] /*"> <th> <xsl:value-of select="name()"/> </th> </xsl:for-each> </tr> xsl:apply-templates/ </table> </body> </html> </xsl:template> <xsl:template match="/*/*"> <tr> <xsl:for-each select="*"> <td> <xsl:value-of select="."/> </td> </xsl:for-each> </tr> </xsl:template> </xsl:stylesheet>