Re: [xsl] nested XML using xslt

Subject: Re: [xsl] nested XML using xslt
From: Michael Dykman <mdykman@xxxxxxxxx>
Date: Thu, 23 Jul 2009 18:56:37 -0400
It would be helpful if you shared your input XML, along with the
stylesheet and the output example, but I think I see what you are
going for..  Here is a fragment demonstrating the pattern I think you
need.

<xsl:template match="list1">
  <list1>
    <text>
       <xsl:value-of select="text"/>
    </text>
    <xsl:apply-templates select="list2/text"/>

  </list1>
</xsl:template>

 - michael dykman

On Thu, Jul 23, 2009 at 6:38 PM, kurps s<kurpss@xxxxxxxxx> wrote:
> Hi
>
> I am trying to create a nested XML list using xslt.The XL should have 4
levels.
>
> <list1>
> <text></text>
> <list2>
> <text></text>
> <list3>
> <text></text>
>
> <list4>
> <text></text>
>
> </list4>
>
> </list3>
> <list3>
> <text></text>
> </list3>
> <list3>
> <text></text>
> </list3>
> </list2>
> <list2>
> <text></text>
> </list2>
> </list1>
>
> Now there can be any number of list elements within each other. Like
> in the example abbove, there can be multiple <list3> within <list2>.
> The trick is to make sure that the first list3 gets closed after
> <list4> , and a new <list3> opens after the first closes.
>
> My XSLT program is just creating a continuous list instead of counting
> the levels.
> <xsl:template match="list1/text">
>                <list1>
>                        <text>
>                                                                      
 <xsl:value-of select="."/>
>                                                        </text>
>                        <xsl:choose>
>
>                        <xsl:apply-templates select="list2/text"/>
>
>                </list1>
>        </xsl:template>
>        <xsl:template match="list2/text">
>                <list2>
>                        <text>
>
>                                        <xsl:value-of select="."/>
>
>                        </text>
> <xsl:apply-templates select=list3/text/>
>                </list2>
>
>        </xsl:template>
>        <xsl:template match="list3/text">
>                <list3>
>                        <text>
>
>                                        <xsl:value-of select="."/>
>
>                        </text>
> <xsl:apply-templates select=list4/text/>
>
>                </list3>
>        </xsl:template>
>        <xsl:template match="list4/text">
>                <list4>
>                        <text>
>
>                                        <xsl:value-of select="."/>
>
>                        </text>
>                </list4>
>        </xsl:template>
>
>
> Can anyone help me here?
>
> Thanks in advance for your help.
>
>



--
 - michael dykman
 - mdykman@xxxxxxxxx

 - All models are wrong.  Some models are useful.

Current Thread