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

[xsl] nested XML using xslt


Subject: [xsl] nested XML using xslt
From: kurps s <kurpss@xxxxxxxxx>
Date: Thu, 23 Jul 2009 17:38:41 -0500

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.


Current Thread
Keywords