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

recursive loop in XSL stylesheet is failing

Subject: recursive loop in XSL stylesheet is failing
From: George <news.net@xxxxxxx>
Date: Thu, 25 Mar 2010 13:33:46 +0100
 recursive loop in XSL stylesheet is failing
Dear all,

What I am trying to accomplish is to transform an account XML file using my XSL stylesheet into a CSV file with following format (please find the content of the files below):
Date; CategoryName; Recipient; Value; Notes


This works already and I want to extend the stylesheet now as follows:
- Each entry in the account file has got a category.
- Each category may have parent categories.
- If a category belongs to higher level categories the CategoryName string should built up with all categories concatenated by colons.


The category relation is stored in a 2nd XML file.

So, the CSV file would have following format:
Date; ParentCategory1:ParentCategoryN:CategoryName; Recipient; Value; Notes


All categories do have a GUID in the ID attribute. The main category does have an empty ParentID attribute whereas sub-categories do have a GUID in the ParentID attribute.

My problem is the recursive loop until all higher level categories are found and concatenated by colons.

It would be fantastic if somebody could help me in order to come up with a working stylesheet.

Thank you very much in advance.
Best regards,
George

structure of the source Account.xml file:
--- start code
<?xml version="1.0"?>
<Account>
  <Entry>
      <ID>4a0d255e-5829-4592-859d-4e397ba5735c</ID>
      <Date>02/10/2010</Date>
      <Recipient>Test Pharmacy, Oakland</Recipient>
      <CategoryID>b1e5e520-50b6-4ff6-b5bc-399ab1b8908e</CategoryID>
      <Value>-19.1</Value>
      <CategoryName>Pharmacy</CategoryName>
  </Entry>
...
</Account>
--- end code

structure of the Categories.xml file:
--- start code
<?xml version="1.0"?>
<Categories Version="3">
<Category ID="095802e5-4d1f-45fe-998d-18c324722a02" Income="False" ParentID="">
<en default="1">Illness expenses</en>
</Category>
<Category ID="b1e5e520-50b6-4ff6-b5bc-399ab1b8908e" Income="False" ParentID="095802e5-4d1f-45fe-998d-18c324722a02">
<en default="1">Pharmacy</en>
</Category>
...
</Categories>
--- end code


my XSL stylesheet so far:
--- start code
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:output method="text"/>
<xsl:template match="Account">
<xsl:apply-templates select="Entry">
<xsl:sort select="number(concat(substring(Date,7,4),substring(Date,1,2),substring(Date,4,2)))" data-type="number"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="Entry">
<xsl:variable name="catid" select="CategoryID"/>
<xsl:param name="parentcatid" select="document('Categories.xml')/Categories/Category[@ID=$catid]/@ParentID"/>


<xsl:param name="parentcat"><xsl:value-of select="CategoryName"/></xsl:param>
<xsl:call-template name="ParentCategories">
<xsl:with-param name="parentcatid" select="."/>
<xsl:with-param name="parentcat" select="."/>
</xsl:call-template>
<xsl:value-of select="Date"/><xsl:text>;</xsl:text><xsl:value-of select="$parentcat"/><xsl:text>;</xsl:text><xsl:value-of select="Recipient"/><xsl:text>;</xsl:text><xsl:value-of select="Value"/><xsl:text>;</xsl:text><xsl:value-of select="Notes"/>
<xsl:text>&#xa;</xsl:text>
</xsl:template>
<xsl:template name="ParentCategories">
<xsl:param name="parentcatid" select="."/>
<xsl:param name="parentcat" select="."/>
<xsl:if test="string($parentcatid)">
<xsl:param name="parentcat"><xsl:value-of select="document('Categories.xml')/Categories/Category[@ID=$parentcatid]/de"/><xsl:text>:</xsl:text><xsl:value-of select="$parentcat"/></xsl:param>
<xsl:param name="parentcatid" select="document('Categories.xml')/Categories/Category[@ID=$parentcatid]/@ParentID"/>


          <xsl:call-template name="ParentCategories">
              <xsl:with-param name="parentcatid" select="."/>
              <xsl:with-param name="parentcat" select="."/>
          </xsl:call-template>
      </xsl:if>
  </xsl:template>
</xsl:stylesheet>
--- end code

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.