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

RE: Testing for Parent Nodes of multiple types

Subject: RE: Testing for Parent Nodes of multiple types
From: Nate Austin <naustin@xxxxxxxxxx>
Date: Wed, 14 Mar 2001 16:28:50 -0600
xsl if parent
Ciaran-
<xsl:if test="contains('p b i u td',name(..))">
should do the trick.  The only thing that might break it is if you had more
multicharacter parent node names that were valid.  Or if, in this example,
it was possible for 't' or 'd' to come up as invalid parent names because
they would come through as 'true()'.  Basically, names that were substrings
of valid names would break it unless you got into concatenating '|' on each
side like so:
<xsl:if test="contains('|p|b|i|u|td|',concat('|',name(..),'|'))">
but then it starts getting more messy again.
Alternatively, you could embed a variable containing a node-set of valid
elements in your stylesheet and check for an element with a matching name
(or just if namespaces will get in your way, use local-name for all cases). 
Of course, which one works best depends on your use case.  If it is exactly
the five elements that you listed in your example, I'd say the last two
might be overkill, but if you have a bunch of them they may be beneficial.
Hope that helps.

-Nate
naustin@xxxxxxxxxx

The opinions expressed are my own and do not reflect those of International
Decision Systems.

>Date: Wed, 14 Mar 2001 16:36:04 -0800
>From: "Ciaran Byrne" <ciaran.byrne@xxxxxxx>
>Subject:  Testing for Parent Nodes of multiple types
>
>Hi all,
>	In my content I am testing for the parent of
>my context node. The parent can be one of several different
>elements.
>
>For example, let's say that the parent of the element 'b' can
>be 'p','b','i','u','td'.
>
>At the moment in my xsl:if I have the node test
>
><xsl:if test="parent::p or parent::b or parent::i or parent::u or
>parent::td">
>...
></xsl:if>
>
>
>Is anyone aware of a more efficient way to implement this ?
>
>Thanks,
>Ciaran.

 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.