Engywook
06-23-2008, 05:55 PM
As I'm trying to wrap my mind around XSLT, there's something that's kinda bothering me.
XML snippet:
<answerList>
<answer>3</answer>
<answer>4</answer>
<answer right="right">5</answer>
</answerList>
XSL snippet, with problem area in bold:
<xsl:for-each select="answerList/answer">
<xsl:if test="@right='right'"><b>* * *</xsl:if>
<!--The selector below displays the first answer, 3, three times. I want to be able to display each answer.-->
<xsl:value-of select="../answer"/>
<xsl:if test="@right='right'">* * *</b></xsl:if>
<br/>
</xsl:for-each>
It appears that the only way to make it work is to add a child node to answer in the XML file:
<answerList>
<answer><answerText>3</answerText></answer>
<answer><answerText>4</answerText></answer>
<answer right="right"><answerText>5</answerText></answer>
</answerList>
...and invoke it with this XSL:
<xsl:for-each select="answerList/answer">
<xsl:if test="@right='right'"><b>* * *</xsl:if>
<xsl:value-of select="answerText"/>
<xsl:if test="@right='right'">* * *</b></xsl:if>
Do I really need to add a child node if I want to get the text out of a node where I'm using for-each? If you feel that this question reflects a lack of real understanding of XSL, you'd be right... I'm new to this and am finding it very counterintuitive.
XML snippet:
<answerList>
<answer>3</answer>
<answer>4</answer>
<answer right="right">5</answer>
</answerList>
XSL snippet, with problem area in bold:
<xsl:for-each select="answerList/answer">
<xsl:if test="@right='right'"><b>* * *</xsl:if>
<!--The selector below displays the first answer, 3, three times. I want to be able to display each answer.-->
<xsl:value-of select="../answer"/>
<xsl:if test="@right='right'">* * *</b></xsl:if>
<br/>
</xsl:for-each>
It appears that the only way to make it work is to add a child node to answer in the XML file:
<answerList>
<answer><answerText>3</answerText></answer>
<answer><answerText>4</answerText></answer>
<answer right="right"><answerText>5</answerText></answer>
</answerList>
...and invoke it with this XSL:
<xsl:for-each select="answerList/answer">
<xsl:if test="@right='right'"><b>* * *</xsl:if>
<xsl:value-of select="answerText"/>
<xsl:if test="@right='right'">* * *</b></xsl:if>
Do I really need to add a child node if I want to get the text out of a node where I'm using for-each? If you feel that this question reflects a lack of real understanding of XSL, you'd be right... I'm new to this and am finding it very counterintuitive.