How to do with XSLT from this
<lines>
<data>
a
</data>
<data>
b
</data>
<data>
a
</data>
<data>
b
</data>
<data>
c
</data>
<data>
b
</data>
<data>
c
</data>
</lines>
this
<resultdata>
b,b,b
</resultdata>
As far as i understand i shal use
<xsl:for-each select="/data">
and
<xsl:if test="data(text)='b'">
and
<xsl:text>, </xsl:text>
But how exactly?
Instead of doing this...
You need to do this...
This is because the initial
/
represents the document node, which is the parent node oflines
. However, it would actually be better if you were positioned on thelines
element at the time (by being in a template that matchedlines
). Then you could just do this (because without the preceding/
the expression is then relative to the current node).To check the text of the node, you need to do this:
Or rather, because you have white-space, you should be doing this:
Or better still, you add the condition to the
xsl:for-each
itself.Try this XSLT to start you going: