Connecting Tech Pros Worldwide Forums | Help | Site Map

Looping through XML

Newbie
 
Join Date: Aug 2007
Posts: 13
#1: Feb 20 '08
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:stylesheet 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.dtd" 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="@password" /> </h1>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

MarkoKlacar's Avatar
Expert
 
Join Date: Aug 2007
Location: Stockholm, Sweden
Posts: 294
#2: Mar 7 '08

re: Looping through XML


Hi,

Did you figure it out, or do you still need help?
Moderator
 
Join Date: Mar 2006
Posts: 1,103
#3: Mar 11 '08

re: Looping through XML


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