Looping through XML

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • li72
    New Member
    • Aug 2007
    • 13

    Looping through XML

    Hi. guys
    The following xslt stylesheet supposed to loop through the xml doc visiting each node, read and write its name and their attributes (userid, password). Actually it visits the only the first node since it performs this statement <xsl:for-each select="data/node1">
    which prevents it from visiting the others. My question is how to amend this code in order to allow it to visit the whole xml doc with any number of nodes with same attributes?
    Any help is really much appreciated
    Cheers

    Here is the xml document

    <?xml version='1.0'?>
    <?xml-stylesheet type="text/xsl" href="xx.xslt"? >
    <data>
    <node1 userid="x" password="y" />
    <node2 userid="xx" password="yy" />
    <node3 userid="xxx" password="yyy" />
    </data>

    Here is the xslt stylesheet
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-
    transitional.dt d" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" indent="yes"/>

    <xsl:template match="/">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <body>
    <xsl:for-each select="data/node1">
    <h2> <xsl:value-of select="local-name()"/> </h2>
    <h1> <xsl:value-of select="@userid " /> </h1>
    <h1> <xsl:value-of select="@passwo rd" /> </h1>
    </xsl:for-each>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>
  • MarkoKlacar
    Recognized Expert Contributor
    • Aug 2007
    • 296

    #2
    Hi,

    Did you figure it out, or do you still need help?

    Comment

    • jkmyoung
      Recognized Expert Top Contributor
      • Mar 2006
      • 2057

      #3
      <xsl:for-each select="data/*[starts-with(local-name(),'node')]">

      Comment

      Working...