I have an XML with records, some records are associated with each other and, as such, I want to group them together in the output.
XML:
<Records>
<Record id="1" group="10" />
<Record id="2" group="20" />
<Record id="3" group="20" />
<Record id="4" group="20" />
</Records>
Currently, I display
<span>1</span><span>2</span><span>3</span><span>4</span>
What I would like to display is (based on the records having the same group)
<span>1</span><span>2-4</span>
I have looked into using preceding-sibling::Record/@group
to see if the grouping has changed between iterations of Record
s but am struggling to figure out how to achieve the 2-4
grouping I require.
Here is what I have so far, interspersed with some comments to illustrate what I am trying to do:
<xsl:for-each select="Records/Record">
<xsl:if test="@group != preceding-sibling::Record/@group">
<!-- obviously here we need 2-4...somehow? -->
<span><xsl:value-of="@id" /></span>
</xsl:if>
</xsl:for-each>
xsl:for-each-group select="Record" group-adjacent="@group">
? – Martin Honnen