|
Subject: RE: [xsl] Recursion Problem From: <Jarno.Elovirta@xxxxxxxxx> Date: Wed, 26 May 2004 08:35:17 +0300 |
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() <= 6]/claim_amount">
<xsl:element name="{concat(name(), '_', position())}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:for-each>
<xsl:if test="count($node-set) < 6">
<xsl:for-each select="(document('')//*)[position() <= (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() < 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) < 6">
<xsl:for-each select="(document('')//*)[position() <= (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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] Recursion Problem, vsubramanian | Thread | RE: [xsl] Recursion Problem, vsubramanian |
| RE: [xsl] Grouping into a table (fo, Daniel Joshua | Date | RE: [xsl] XHTML [WAS: Grouping into, Daniel Joshua |
| Month |