Abe Scott wrote:
I'm
trying to create a field that will increase by 1 for every fourth
record, ordered by \CommlVeh\ItemIdInfo\SystemId (We print 4 records
per page) The records may be in random order and there may be missing
id's in the list.
So that my output would be similar to:
<Vehicle systemId="1" pageNum="1">
<Vehicle systemId="2" pageNum="1">
<Vehicle systemId="3" pageNum="1">
<Vehicle systemId="4" pageNum="1">
<Vehicle systemId="5" pageNum="2">
<Vehicle systemId="6" pageNum="2">
Data Sample:
<CommlVeh id="207507" LocationRef="219009">
<ItemIdInfo>
<SystemId>1</SystemId>
</ItemIdInfo>
<Manufacturer>Make</Manufacturer>
<Model>Model</Model>
<ModelYear>2001</ModelYear>
<VehBodyTypeCd>BType</VehBodyTypeCd>
<TerritoryCd>124</TerritoryCd>
<VehIdentificationNumber>111111</VehIdentificationNumber>
</CommlVeh>
Here is an XSLT 2.0 solution that performs two steps, sorts first, then
groups:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output indent="yes"/>
<xsl:param name="n" as="xs:integer" select="4"/>
<xsl:template match="root">
<xsl:variable name="sorted-vehicles">
<xsl:perform-sort select="CommlVeh">
<xsl:sort select="ItemIdInfo/SystemId" data-type="number"/>
</xsl:perform-sort>
</xsl:variable>
<xsl:for-each-group select="$sorted-vehicles/CommlVeh"
group-by="(position() - 1) idiv $n">
<xsl:for-each select="current-group()">
<Vehicle systemId="{ItemIdInfo/SystemId}"
pageNum="{current-grouping-key() + 1}"/>
</xsl:for-each>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>
--
Martin Honnen
http://msmvps.com/blogs/martin_honnen/
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--