xsl-list
[Top] [All Lists]

[xsl] nested XML using xslt

2009-07-23 18:39:11
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.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>