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

Re: How to get the preceding-sibling of parameter cont

Subject: Re: How to get the preceding-sibling of parameter context node[URGENT]
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 14 Feb 2002 11:13:25 -0500
count preceding sibling with attribute
Hi Deep,

At 01:56 AM 2/14/02, you wrote:
<xsl:template name="mytemplate">
<xsl:param name="contextnode"/>
<xsl:for-each select="$contextnode">
//How to get the preceding-sibling of context node
here following does not work

<xsl:variable name="cnt"
select="count(preceding-sibling::$contextnode[@name='data'])"/>

This doesn't work because '$contextnode', a variable reference, is not a valid node test. (A node test is the part of a location step, in an XPath, that comes after the '::', which is part of the axis identifier.) But you have the correct axis.


count(preceding-sibling::*[@name='data']) will count those sibling elements preceding the context node that have a @name attribute = 'data'. The node test here is '*' (tests true for any node of the primary node type of the axis, here elements).

count(preceding-sibling::mything[@name='data']) will count those 'mything' sibling elements preceding the context node that have a @name attribute = 'data'. The node test here is 'mything' (tests true for any node named 'mything' on the axis).

count(preceding-sibling::*[name()=name($contextnode)][@name='data']) will count those sibling elements preceding the context node whose name is the same as that of $contextnode, and that have a @name attribute = 'data'. The node test here is again '*', but you are then filtering the elements by testing their names against the name of $contextnode.

I don't know if you actually need the [@name='data'] test, which checks the value of a @name attribute. If that's what you want to do, great.

I hope that helps. You might find a good breakdown of how XPath works, like that in Mike Kay's book, to be illuminating.

Cheers,
Wendell


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread

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
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.