On Mon, 9 Feb 2004, Kielen, Agnes wrote:

> Try:
> 
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> <xsl:template match="/document">
>          <document>
>               <xsl:for-each select="node[(position() mod 2) = 1]">
>                   <group>
>                       <xsl:copy-of select=". | following-sibling::node[1]"/>
>                    </group>
>               </xsl:for-each>
>     </document>
>   </xsl:template>
> 
> </xsl:stylesheet>

Thanks for the advice. What if I want the number of <node> nodes to go
to a single <group> node to depend on some attribute in the original XML
document? Say, for example:

<document>
  <nodes width="3">
    <node>1</node>
    <node>2</node>
    <node>3</node>
    <node>4</node>
    <node>5</node>
    <node>6</node>
    <node>7</node>
    <node>8</node>
  </nodes>
</document>

How can I make this transform to this?

<document>
  <group>
    <node>1</node>
    <node>2</node>
    <node>3</node>
  </group>
  <group>
    <node>4</node>
    <node>5</node>
    <node>6</node>
  </group>
  <group>
    <node>7</node>
    <node>8</node>
  </group>
</document>

In other words, the "length" attribute defines how many <node> nodes go
under a single <group> node. If there are not enough nodes, then all
that are left are used. Is this possible in XSLT?

Joona Palaste
[EMAIL PROTECTED]


Reply via email to