[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Recursion Problem

Subject: RE: Recursion Problem
From: <Jarno.Elovirta@xxxxxxxxx>
Date: Wed, 26 May 2004 08:35:17 +0300
RE:  Recursion Problem
Hi,

> I am having a problem with recursion. 
> A student can have multiple claims & I am trying to group 6 
> claims in every
> node. I tried to do recursion but, i  lose one node always with every
> recursion

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
  <xsl:key name="name" match="service" use="name"/>
  <xsl:template match="service_list">
    <serv_list>
      <xsl:for-each select="service[generate-id(.) = generate-id(key('name', name))]">
        <xsl:call-template name="group">
          <xsl:with-param name="node-set" select="key('name', name)"/>
        </xsl:call-template>
      </xsl:for-each>
    </serv_list>
  </xsl:template>
  <xsl:template name="group">
    <xsl:param name="node-set"/>
    <final_serv_list>
      <xsl:copy-of select="$node-set[1]/name"/>
      <xsl:copy-of select="$node-set[1]/cr_case_id_fk"/>
      <xsl:for-each select="$node-set[position() &lt;= 6]/claim_amount">
        <xsl:element name="{concat(name(), '_', position())}">
          <xsl:value-of select="."/>
        </xsl:element>
      </xsl:for-each>
      <xsl:if test="count($node-set) &lt; 6">
        <xsl:for-each select="(document('')//*)[position() &lt;= (6 - count($node-set))]">
          <serv_list/>
        </xsl:for-each>
      </xsl:if>
    </final_serv_list>
    <xsl:if test="count($node-set) > 6">
      <xsl:call-template name="group">
        <xsl:with-param name="node-set" select="$node-set[position() >= 7]"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>

or if the services are always ordered as they are in your example

  <xsl:template match="service_list">
    <serv_list>
      <xsl:apply-templates select="service[1]"/>
    </serv_list>
  </xsl:template>
  <xsl:template match="service">
    <xsl:variable name="group" select=". | following-sibling::service[position() &lt; 6][name = current()/name]"/>
    <final_serv_list>
      <xsl:copy-of select="name"/>
      <xsl:copy-of select="cr_case_id_fk"/>
      <xsl:for-each select="$group/claim_amount">
        <xsl:element name="{concat(name(), '_', position())}">
          <xsl:value-of select="."/>
        </xsl:element>
      </xsl:for-each>
      <xsl:if test="count($group) &lt; 6">
        <xsl:for-each select="(document('')//*)[position() &lt;= (6 - count($group))]">
          <serv_list/>
        </xsl:for-each>
      </xsl:if>
    </final_serv_list>
    <xsl:apply-templates select="following-sibling::service[count($group)]"/>
  </xsl:template>

Hope this helps,

Jarno - Simon Eve: December 2002 Mix

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.