Re: [xml-dev] XSLT 2.0: Definition of a structure and its use

From
Agnisys Technology (P) Ltd. <>
To
David Carlisle <>
Date
2005-09-14T14:18:52Z
ID
<>
Thread
Re: [xml-dev] XSLT 2.0: Definition of a structure and its use
Hi David,
  I knew I'll get flak for this, but I was really stuck!

  The output I get using your stylesheet is :
Register : reg_1 Offset = 5 Prev-Sibling count = 0 
Register : reg_2 Offset = 5 Prev-Sibling count = 1 
Register : reg_10 Offset = Prev-Sibling count = 2 
Register : reg_20 Offset = Prev-Sibling count = 3 
Register : reg_3 Offset = 5 Prev-Sibling count = 4 

Note that the parent attribute "offset" is not being accessed by reg_10 and reg_20 nodes.
Any ideas, how to solve that?

Anupam.



--- David Carlisle <> wrote:

> 
> As others have explained in answer to your previous question, you can do
> this in two passes, first copying the branch, then processing the new
> input tree, but in this simple case you can do it in one pass, without
> using any variables:
> 
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
> 
> <xsl:key name="r" match="regdef" use="@name"/>
> 
>     <xsl:template match="*">
>         <xsl:copy>
>             <xsl:copy-of select="@*"/>
>             <xsl:apply-templates/>
>         </xsl:copy>
>     </xsl:template>
>     
>     <xsl:template match="reg[@href]">
>         <xsl:apply-templates select="key('r',@href)/*">
>         <xsl:with-param name="c"
> select="count(preceding-sibling::reg[not(@href)]|key('r',preceding-sibling::reg/@href)/*)"/>
>         </xsl:apply-templates>
>     </xsl:template>
>     
>     <xsl:template match="regdef"/>
>     
>     <xsl:template match="reg">
>         <xsl:param name="c" select="0"/>
>         <xsl:text>
</xsl:text>
>         <br/>Register : <xsl:value-of select="."/>
>         <xsl:text/> Offset = <xsl:value-of select="../@offset"/>
>         <xsl:text/> Prev-Sibling count = <xsl:value-of
> select="$c+count(preceding-sibling::reg[not(@href)]|key('r',preceding-sibling::reg/@href)/*)"/>
>     </xsl:template>
> 
> </xsl:stylesheet>
> 
> ________________________________________________________________________
> This e-mail has been scanned for all viruses by Star. The
> service is powered by MessageLabs. For more information on a proactive
> anti-virus service working around the clock, around the globe, visit:
> http://www.star.net.uk
> ________________________________________________________________________
> 




		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com