[xsl] make recursive call

Subject: [xsl] make recursive call
From: "mary liu" <maryliu99@xxxxxxxxx>
Date: Fri, 25 Aug 2006 10:33:31 -0400

I have a oldxml.xml file need to be converted to the newxml.xml file.  I can
only convert it to 2 levels and dont know how to make it recursive. I don't
know how deepth it is. My convert file is like this:


<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl=" http://www.w3.org/1999/XSL/Transform";> <xsl:template match="/">

select="ResultSet/data_service/Employeeprofile/row[@lev = 2]"/>

<xsl:template match="row">
  <xsl:element name="branch">
  <xsl:attribute name="id">
              <xsl:value-of select="@emp_name" />

      <xsl:value-of select="@emp_name"/>
     <xsl:call-template name="IterateRows">
      <xsl:with-param name="rows" select="following-sibling::node()"/>
<xsl:template name="IterateRows">
  <xsl:param name="rows"/>
  <xsl:if test="$rows[1]/@lev = 3">
        <xsl:value-of select="$rows[1]/@emp_name"/>

    <xsl:call-template name="IterateRows">
      <xsl:with-param name="rows" select="$rows[position()> 1]"/>


<row emp_name="one" org_cd="73700" rpt_to_org_cd="11111"  lev="2" />
<row emp_name="four" org_cd="73656" rpt_to_org_cd="73700" lev="3"  />
<row emp_name="five" org_cd="75425" rpt_to_org_cd="73700" lev="3"  />
<row emp_name="three" org_cd="73723" rpt_to_org_cd="11111"  lev="2" />
<row emp_name="two" org_cd="73708" rpt_to_org_cd="11111"  lev="2" />
<row emp_name="Six" org_cd="73651" rpt_to_org_cd="73708" lev="3"  />
<row emp_name="Seven" org_cd="73632" rpt_to_org_cd="73651" lev="4"  />
<row emp_name="Eight" org_cd="73229" rpt_to_org_cd="73651" lev="4"  />
<row emp_name="nine" org_cd="74023" rpt_to_org_cd="73651" lev="4"  />
<row emp_name="ten" org_cd="73989" rpt_to_org_cd="11111"  lev="2" />

lev="2" is same level. Then lev=3, lev=4...
every level may have leaves or may not have leaves, like emp_name="two", it
has no leaf.

Attribute rpt_to_org_cd is the value pointing to the parent. for example
emp_name="Eight", rpt_to_org_cd ="73651", its parents' node is same as
emp_name="Seven" and emp_name="nine" which is emp_name="Six" org_cd="73651"

So the newxml.xml should be like this:

<ResultSet> <branch id="one"> <branchText>one</branchText> <leaf> <leafText>four</leafText> </leaf> <leaf> <leafText>five</leafText> </leaf> </branch>

  <branch id="three">

  <branch id="two">
      <branch id="Six">

   <branch id="ten">


Is there anybody helping me? Thanks in advance.


Current Thread