Flat -> hierarchy.

Subject: Flat -> hierarchy.
From: Paul Tchistopolskii <paul@xxxxxxx>
Date: Wed, 07 Jun 2000 14:49:44 -0700
Appears to be a FAQ ?

 
> All that I realy neef to know is how I can go about calling The same
> function and moving down to the next node.
> 
> <Node>
> A1
> </Node>
> <Node>
> A2
> </Node>
> <Node>
> A3
> </Node>
> 
> So I Can Get
> 
>  <A1><A2><A3></A3></A2></A1>

--------------- flat.xml:

<doc>

<Node> 
        A1 
</Node> 
<Node> 
        A2 
</Node> 
<Node> 
        A3 
</Node> 


</doc>


--------------- hier.xsl

<xsl:stylesheet 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
 version="1.0">


<xsl:template match="/doc">

 <xsl:call-template name="level">
  <xsl:with-param name="node" select="/doc/Node[1]"/>
 </xsl:call-template>

</xsl:template>


<xsl:template name="level">
        <xsl:param name="node"/>

 <xsl:variable name="n" select="normalize-space($node)"/>
 <xsl:element name="{$n}">

  <xsl:if test="$node/following::Node">

   <xsl:call-template name="level">
   <xsl:with-param name="node" select="$node/following::Node"/>
   </xsl:call-template>

  </xsl:if>

 </xsl:element>

</xsl:template>

</xsl:stylesheet>

---- result:

<?xml version="1.0" encoding="utf-8"?>
<A1><A2><A3/></A2></A1>



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


Current Thread