Click to See Complete Forum and Search --> : XPath of nested for-each


samiei
04-10-2007, 09:35 AM
Hi;
I am going to transform a relational xml by xslt using nested for-each. The xml document is such as below (I may not change this structure!):

<root>
<parent>
<pid>1</pid>
<name>John</name>
<family>Smith</family>
.
.
.
</parent>
<parent>
<id>2</id>
<name>David</name>
<family>Green</family>
.
.
.
</parent>
.
.
.
<child>
<id>1</id>
<lesson>Mathematics</lesson>
<mark>18</mark>
.
.
.
</child>
<child>
<id>1</id>
<lesson>Physics</lesson>
<mark>15</mark>
.
.
.
</child>
<child>
<id>1</id>
<lesson>Chemistry</lesson>
<mark>17</mark>
.
.
.
</child>
<child>
<id>2</id>
<lesson>Mathematics</lesson>
<mark>9</mark>
.
.
.
</child>
<child>
<id>2</id>
<lesson>Physics</lesson>
<mark>11</mark>
.
.
.
</child>
<child>
<id>2</id>
<lesson>Chemistry</lesson>
<mark>12</mark>
.
.
.
</child>
.
.
.
</root>


And my xslt:

<xsl:for-each select="/root/parent">

ID: <xsl:value-of select="pid" /><br>
Name: <xsl:value-of select="name" /><br>
Family: <xsl:value-of select="family" /><br>

<xsl:for-each select="/root/child[id=pid]">
<xsl:value-of select="lesson" />:
<xsl:value-of select="mark" /><br>
</xsl:for-each>

</xsl:for-each>

But unfortunately, this does not work properly. The main problem is from the xpath command of interior for-each.
I am much obliged to you for your great attention.

Regards,
M.Sadegh Samiei