[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XSLT 2.0: Definition of a structure and its use

  • To: David Carlisle <davidc@n...>
  • Subject: Re: XSLT 2.0: Definition of a structure and its use
  • From: "Agnisys Technology \(P\) Ltd." <agnisys@y...>
  • Date: Wed, 14 Sep 2005 07:18:52 -0700 (PDT)
  • Cc: xml-dev@l...
  • Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=sBd6H94kjFgt0bvaJdS9Aa6LlCfqaudBG/95A0KcAlYXztZ4Ch00HSQjfC7/F5bR+qxxYxl1WyLkBiIJv9SJf84df3S9t3lkMmUGrnbKP5NFFITUupYEHtO9Q4mubViUaFlC3Igsy8Zl7z5KLczL9Wxaz87IlZY5qbn//MjhGsc= ;
  • In-reply-to: <200509141405.PAA15941@p...>

xslt count parent
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 <davidc@n...> 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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.