Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. Generic XSLT

Generic XSLT

Scheduled Pinned Locked Moved XML / XSL
xmlhtmlwpfregexquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gktony
    wrote on last edited by
    #1

    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

    P 1 Reply Last reply
    0
    • G Gktony

      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

      P Offline
      P Offline
      Prateek G
      wrote on last edited by
      #2

      <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>

      G 1 Reply Last reply
      0
      • P Prateek G

        <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>

        G Offline
        G Offline
        Gktony
        wrote on last edited by
        #3

        Thanks for that it works. However when I am trying to add <xsl:sort select="*"/> after the <xsl:for-each select="*"> to sort by the first item doesn't work. Am I missing something? Thanks

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups