This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How to get the preceding-sibling of parameter context node[URGENT]


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@mulberrytech.com
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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]