[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Create xml file with recursive childnodes


Subject: [xsl] Create xml file with recursive childnodes
From: chun ji <cji_work@xxxxxxxxx>
Date: Thu, 7 Aug 2008 16:31:08 -0700 (PDT)

Hi all, 

I have been thinking this for days, but still not sure
what are the best way to fix it. ( I am using Saxon
2.0 on Window XP and Linux Box. JDK version is 1.6.0 )


The input XML file is something as:   
" 
<Objs> 
    <obj name="a" child="b"/>
    <obj name="b" child="c"/>
    <obj name="b" child="d"/>
    <obj name="c" child="e"/>
</Objs> 
". let's say that xml file has ONLY 1 root node.  
 
The output XML file would be: 
"
<Obj name="a">
   <Obj name="b">
       <Obj name="c">
          <Obj name="e"/>
       </Obj>
       <Obj name="d"/>
   </Obj>
</Obj>
"

In my opinion, the XSL file would be something as: 
" 
  ...

  <xsl:template match="/">
         <xsl:value-of select="dumpChildNode(?,...)"/>
  </xsl:template>

   <xsl:function name="dumpChildNode" as="...">
       <xsl:param name="name" .../>
       <xsl:param name="?" .../>
       
       <Obj><xsl:attribute name="name">
              <xsl:value-of select="@name"/>
            </xsl:attribute>

       // Find the child node(s) and call the
dumpChildNode(..)
       ....?
       ....?
       <xsl:value-of select="dumpChildNode(?,)"/>
       <Obj> 
 </xsl:function>
</xsl:stylesheet>
" 

Does someone know how to finish the rest of code? Or
you have a better idea to solve the whole problem. 



Thanks a lot 


Chun  


Current Thread
Keywords