Note: Solution should be in XSLt 1.0
I'm a complete novice with XSLT so apologies if solutions to other questions relating to loops would work for my problem but I've had no luck so far.
I have an XML file with multiple nodes such as the following:
<Roles>
<field name="linecode" instance="1" value="EY"/>
<field name="number" instance="1" value="265"/>
<field name="linecode" instance="2" value="PK"/>
<field name="number" instance="2" value="123"/>
<field name="abc" instance="1" value="123"/>
<field name="xyz" instance="1" value="123"/>
</Role>
I need to loop through these nodes and print <field name="linecode">
along with its matching instance no <field name="number">
. However, if I use a for-each loop it will iterate through the <field name="linecode">s
fine but print the same <field name="number">
is not working.
Is there any way I can sync them up so that, for example the output will be
EY - 265
PK - 123
I have also tried to use the following-sibling
but its not working for me.. Any help is highly appreciated. .
Here's my sample xslt.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Roles">
<xsl:for-each select="field[@name='linecode']">
<xsl:value-of select="@value"/>
<xsl:text> - </xsl:text>
<xsl:value-of select="field[@name='number' and instance='@instance']"/>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
If anyone could think an alternative to loops which would work as well I would appreciate it.