Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: XSLT challenge problem

From: Mukul Gandhi@-----------.---------.---
To: 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
> 


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent