Reputation: 473
This is my XML code:
<NTC_LIGHTLISTPRODUCT>
<LIGHT_DESCRIPTION_LIST>
<LIGHT_DESCRIPTION>
<LIGHT_COLOUR>R</LIGHT_COLOUR> <-- Colour 1
</LIGHT_DESCRIPTION>
<LIGHT_DESCRIPTION>
<LIGHT_COLOUR>G</LIGHT_COLOUR> <-- Colour 2
</LIGHT_DESCRIPTION>
</LIGHT_DESCRIPTION_LIST>
<LIGHT_INFORMATION>
<SIGNAL_SEQUENCE>01.0+(01.0)</SIGNAL_SEQUENCE>
<SECTOR_LIST>
<LIGHT_SECTOR>
<SECTOR1_2>UNKNOWN</SECTOR1_2> <-- Characteristic 1
<SECTOR2_2>UNKNOWN</SECTOR2_2>
</LIGHT_SECTOR>
<LIGHT_SECTOR>
<SECTOR1_2>62</SECTOR1_2> <-- Characteristic 2
<SECTOR2_2>83</SECTOR2_2>
</LIGHT_SECTOR>
</SECTOR_LIST>
</LIGHT_INFORMATION>
</NTC_LIGHTLISTPRODUCT>
My xslt code:
<xsl:for-each select="LIGHT_SECTOR">
<xsl:variable name="Sectors" select="."/>
<xsl:text>VIS </xsl:text>
<xsl:text> </xsl:text>
<xsl:value-of select="SECTOR1_2"/>
<xsl:text>-</xsl:text>
<xsl:value-of select="SECTOR2_2"/><br/>
</xsl:for-each>
This is the output:
VIS UNKNOWN-UNKNOWN
VIS 62-83
I would:
VIS R UNKNOWN-UNKNOWN <-- concat of "Vis" + Colour 1 + Characteristic 1
VIS G 62-83 <-- concat of "Vis" + Colour 2 + characteristic 2
Upvotes: 0
Views: 50
Reputation: 70648
I don't think this is a grouping issue, not if there is a 1-1 correlation between LIGHT_DESCRIPTION and LIGHT_SECTOR
Anyway, you can look up the relevant LIGHT_DESCRIPTION by means of a key. In this case you want to look them up by their ordering:
<xsl:key name="light" match="LIGHT_DESCRIPTION" use="count(preceding-sibling::LIGHT_DESCRIPTION)" />
Then, to get the relevant light value when you iterate over your LIGHT_SECTOR just use the key to look them up based on the position
<xsl:value-of select="key('light', position() - 1)/LIGHT_COLOUR" />
Try this XSLT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" indent="yes"/>
<xsl:key name="light" match="LIGHT_DESCRIPTION" use="count(preceding-sibling::LIGHT_DESCRIPTION)" />
<xsl:template match="/">
<xsl:apply-templates select="//SECTOR_LIST" />
</xsl:template>
<xsl:template match="SECTOR_LIST">
<xsl:for-each select="LIGHT_SECTOR">
<xsl:variable name="Sectors" select="."/>
<xsl:text>VIS </xsl:text>
<xsl:value-of select="key('light', position() - 1)/LIGHT_COLOUR" />
<xsl:text> </xsl:text>
<xsl:value-of select="SECTOR1_2"/>
<xsl:text>-</xsl:text>
<xsl:value-of select="SECTOR2_2"/><br/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Upvotes: 1