Reputation: 4003
I have the following line of xml that I'm trying transform using XSLT but I'm having trouble. The line is
<app>
<lem>text</lem>
<rdg wit="V" type="add.">text1</rdg>
<rdg wit="S" type="add.">text2</rdg>
<rdg wit="SV" type="add.">text3</rdg>
</app>
I have several of these app elements
and then there can be between 1 and 4 rdg
elements within them, so I'm trying to write a foreach
statement within a foreach
statement but it is not working.
I want to say:
<xsl:for-each select="//tei:app">
<li><xsl:value-of select="tei:lem"/><xsl:text>] </xsl:text>
<xsl for-each select="tei:rdg"> <!--I hoping this would loop through each <rdg> within a given <app> element -->
<xsl:value-of select="//tei:rdg"/>
<xsl:value-of select="//tei:rdg/@type"/>
<xsl:value-of select="//tei:rdg/@wit"/>
</xsl:for-each>
</li>
</xsl:for-each>
But right now this is not working. As it currently stands - this does the right number of loops but for every instance of rdg
I'm getting the value of the fist rdg
. But if I remove the double slashes in the three value-of
elements, then I don't get any values.
Can you spot something I'm doing wrong? Sometimes I get pretty confused about the slash, double slash, no slash use in xpath -- could I be messing up there?
Thanks for your help.
Upvotes: 0
Views: 214
Reputation: 26930
Try this :
<xsl:for-each select="//tei:app">
<li><xsl:value-of select="tei:lem"/><xsl:text>] </xsl:text>
<xsl for-each select="tei:rdg"> <!--I hoping this would loop through each <rdg> within a given <app> element -->
<xsl:value-of select="."/>
<xsl:value-of select="@type"/>
<xsl:value-of select="@wit"/>
</xsl:for-each>
</li>
</xsl:for-each>
In your inner loop your "current()" node is a tei:rdg node. So . access it's contents while @ access the various attributes.
Upvotes: 1