Reputation: 1126
Example xml:
<body>
<macroField dictTag="comment"></macroField>
<macroField dictTag="comment"></macroField>
<macroField dictTag="comment"></macroField>
<macroField dictTag="comment"></macroField>
<macroField dictTag="stopName">Old Wisconsin </macroField>
<macroField dictTag="stopName">Another stop</macroField>
<macroField dictTag="stopName">Another stop</macroField>
</body>
I need to transform comments into divs but after the last comment I want to add extra text "STOPS: " before I show stop.
I tried this xsl for comment tag but for some reason it evaluates to true for every comment tag, not just for the last one:
<xsl:template match="*[@dictTag = 'comment']">
<div class="comment_line">
<xsl:value-of select="."/>
</div>
<xsl:if test="following-sibling::macroField/@dictTag = 'stopName'">
<p>STOPS</p>
</xsl:if>
</xsl:template>
What is wrong with my xsl:if test? How do I modify it so that if statement evaluates to true only for the last comment element?
Upvotes: 1
Views: 2046
Reputation: 12075
Following sibling could refer to ANY following sibling, not just the immediate one- a younger brother is still younger even if your the eldest, and he's the youngest of 3. Try this:
following-sibling::macroField[1]/@dictTag = 'stopName'
Which selects on the first following sibling.
Upvotes: 3