xsl-list
[Top] [All Lists]

Re: [xsl] question on EXSLT data partitioning

2010-10-20 12:57:25
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(_dot_)amoureux(_at_)douane(_dot_)finances(_dot_)gouv(_dot_)fr>
To:         xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Date:       10/20/2010 03:43 PM
Subject:    Re: [xsl] 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(_dot_)Honnen(_at_)gmx(_dot_)de>
À : <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Envoyé : mercredi 20 octobre 2010 15:32
Objet : Re: [xsl] 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/

--~------------------------------------------------------------------
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>
--~--


--~------------------------------------------------------------------
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>
--~--




--~------------------------------------------------------------------
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>
--~--