[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: every 4th record increase counter

Subject: Re: every 4th record increase counter
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Tue, 01 Sep 2009 18:44:22 +0200
Re:  every 4th record increase counter
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/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.