Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] every 4th record increase counter

From: Martin Honnen <Martin.Honnen@---.-->
To: xsl-list@-----.------------.---
Date: 9/1/2009 4:45:00 PM
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@l...>
--~--



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent