On Mon, 9 Feb 2004 [EMAIL PROTECTED] wrote:

> Lainaus Joona Palaste <[EMAIL PROTECTED]>:
> 
> < 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>
> 
> Something like (not tested):
> 
>   <xsl:template match="/document/nodes">
>  <xsl:variable name="module" select="@width"/>
>             <document>
>                  <xsl:for-each select="node[(position() mod $module) = 1]">
>                     <group>
>                          <xsl:copy-of select=". |
>                    following-sibling::node[position()&lt;$module]"/>
>                      </group>
>                 </xsl:for-each>
>                 </document>
>                </xsl:template>
> 
> 
> 
> <
> < 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?

That's great, thanks Agnes and Jarkko!

Joona Palaste
[EMAIL PROTECTED]

Reply via email to