Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - XSLT challenge problem [Thread Next] RE: XSLT challenge problemTo: NULL Date: 9/4/2004 9:33:00 AM Hi Duke,
Please try this XSL -
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="total" select="count(//c) + count(//d) + count(//f)" />
<W>
<xsl:call-template name="generateTags">
<xsl:with-param name="x" select="$total" />
</xsl:call-template>
</W>
</xsl:template>
<xsl:template name="generateTags">
<xsl:param name="x" />
<xsl:if test="$x > 0">
<X id="{$x}"/>
<xsl:call-template name="generateTags">
<xsl:with-param name="x" select="$x - 1" />
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Regards,
Mukul
"Duke Hamacher" wrote:
> In general, I need to convert the number of occurences of several
> nodes combined in the input document into a single numerical sequence
> for sibling nodes in the output. Consider the following input XML:
>
> <a>
>
> <b>
> <c/>
> <d/>
> <e>
> <f/>
> <f/>
> </e>
> </b>
>
> <b>
> <c/>
> <d/>
> <e>
> <f/>
> <f/>
> </e>
> </b>
>
> <b>
> <c/>
> <d/>
> <e>
> <f/>
> <f/>
> </e>
> </b>
>
> </a>
>
> OK, my new XML after XSLT needs to contain a number of sibling <X/>
> elements. The exact number of occurances of this element will be
> equal to the number of occurances of <c/>, <d/>, and <f/> combined
> ("Q"). Moreover, an attribute named "id", which is required on all
> <X/> elements, will contain a unique identifier (a number) whose
> maximum value naturally should always be equal to the number of <X/>
> elements in the output.
>
> <W>
> <X id="Q"/>
> <X id="Q - 1"/>
> <X id="Q - 2"/>
> ...
> </W>
>
> Can somebody come up with a general solution? Thanx.
>
> Duke Hamacher
>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
