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

recursion with xsl:apply-templates

Subject: recursion with xsl:apply-templates
From: Volker Witzel <volker.witzel@xxxxxxxxxxxx>
Date: Wed, 27 Aug 2003 11:14:25 +0200
recursion in xsl
Hi,

I have a problem with a recursion and I don't have a clue, why my solution does not work. I did not find anything on the web, so your help is greatly appreciated.

The problem:
I need to perform an XML to XML transformation to augment the data with unique keys.
The structure is as follows:
<transformation>
<IRF>
<HEADER>
<REC_IR020_01 index="1">
<UNB_S002_0004>16</UNB_S002_0004>
...
</REC_IR020_01>
<REC_IR030_01 index="1">
<UNH_0062>03081402160553</UNH_0062>
...
</REC_IR030_01>
...
</IRF>
<id_list>
<id>2003-08-25 15:36:59.534096</id>
...
</id_list>
</transformation>


I do not know all tag names, but I know that I have some elements with an index attribute, which I need to transform to
<REC_IR020_01>
<id>2003-08-25 15:36:59.534096</id>
<UNB_S002_0004>16</UNB_S002_0004>
...
</REC_IR020_01>
So I have to strip the index attribute and fetch one unique id from the id_list for each occurence of an index attribute.


My Solution:
I thought it's startightforward with XSL. My code:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xslt">
<xsl:output method="xml" indent="yes" encoding="UTF-8" omit-xml-declaration="no" xalan:indent-amount="2" />
<xsl:strip-space elements="*"/>
<xsl:template match="/transformation">
<xsl:apply-templates select="IRF"/>
</xsl:template>
<xsl:template match="IRF">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="descendant::*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="node()">
<xsl:param name="idCount" select="1"/>
<xsl:choose>
<xsl:when test="@index">
<xsl:copy>
<xsl:element name="test"><xsl:value-of select="$idCount"/></xsl:element>
<xsl:call-template name="addIdElement">
<xsl:with-param name="idCount" select="$idCount"/>
</xsl:call-template>
<xsl:apply-templates select>
<xsl:with-param name="idCount" select="$idCount + 1"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates>
<xsl:with-param name="idCount" select="$idCount"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="addIdElement">
<xsl:param name="idCount"/>
<xsl:element name="id">
<xsl:copy-of select="/transformation/id_list/id[$idCount]"/>
</xsl:template>
</xsl:stylesheet>


My problem is that the lines
<xsl:apply-templates select>
<xsl:with-param name="idCount" select="$idCount + 1"/>
</xsl:apply-templates>
do not call the template with the inceremnted parameter, so it always runs with the default value 1.


Any ideas where my brain is scrumbled?
Volker.



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list


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.