[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: question on EXSLT data partitioning
Erwan, I really like xsl:key, see my posting on XSLT pointers: http://www.biglist.com/lists/lists.mulberrytech.com/xsl-list/archives/201009/ msg00179.html I tried your proposal with xsl:key. But your solution does not work for xsltproc, saxon, xalan and DataPower XSLT processor. This is the result returned: <all><arguments/><arguments/><arguments/></all> The reason why it does not work seems to be given by the comments of the others in this thread (position() always being 1). Perhaps you may want to try in your environment. I had to hardcode the value of 3 for $N in xsl:key because xalan complained about it: XSLT Error (javax.xml.transform.TransformerConfigurationException): [ERR 0024] The 'use' attribute of xsl:key can not contain a VariableReference. Input data: <root> <data> <Entity>1</Entity> <Entity>2</Entity> <Entity>3</Entity> <Entity>4</Entity> <Entity>5</Entity> <Entity>6</Entity> <Entity>7</Entity> <Entity>8</Entity> <Entity>9</Entity> <Entity>10</Entity> <Entity>11</Entity> </data> </root> Here is the stylesheet: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:output omit-xml-declaration="yes" /> <xsl:variable name="N" select="3"/> <xsl:key name="part" match="Entity" use="(position() - (position() mod 3)) div 3 "/> <xsl:template match="Entity"> <argument><xsl:value-of select="."/></argument> </xsl:template> <xsl:template match="/root/data"> <all> <xsl:for-each select="Entity[position() mod $N = 0]"> <arguments> <xsl:apply-templates select="key('part',position() div $N)"/> </arguments> </xsl:for-each> </all> </xsl:template> </xsl:stylesheet> Mit besten Gruessen / Best wishes, Hermann Stamm-Wilbrandt Developer, XML Compiler, L3 Fixpack team lead WebSphere DataPower SOA Appliances ---------------------------------------------------------------------- IBM Deutschland Research & Development GmbH Vorsitzender des Aufsichtsrats: Martin Jetter Geschaeftsfuehrung: Dirk Wittkopp Sitz der Gesellschaft: Boeblingen Registergericht: Amtsgericht Stuttgart, HRB 243294 From: Erwan AMOUREUX <erwan.amoureux@xxxxxxxxxxxxxxxxxxxxxxx> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Date: 10/20/2010 03:43 PM Subject: Re: question on EXSLT data partitioning I frequently use this with msmxl or altova engine. In that case, it's a 'default' position() by parent node , using the xml tree entirely . ----- Message d'origine ----- De : "Martin Honnen" <Martin.Honnen@xxxxxx> @ : <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Envoyi : mercredi 20 octobre 2010 15:32 Objet : Re: question on EXSLT data partitioning > Erwan AMOUREUX wrote: >> Fisrt sorry for my english, litlle out of practice >> >> Second, for this data volume , it would be nice to use key, isn't it ? >> You cannot use a variable for modulo but that accelerate processing >> >> <xsl:key name="part" match="Entity" use="(position() - (position() mod 1000)) div 1000 "> >> [...] >> <xsl:for-each select="Entity[position() mod 1000 = 0]"> >> <arguments> >> <xsl:apply-templates select ="key('part',position() div 1000) "> </arguments> >> </xsl:for-each> >> >> [...] >> >> I can't test (and make always error with modulo and other...) but that's the scheme > > I agree that using a key makes sense but as far as I understand it when > you use position() in the "use" expression of an "xsl:key" element it > should be always 1. I have however found XSLT processors that implement > that differently. > > -- > > Martin Honnen > http://msmvps.com/blogs/martin_honnen/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|