[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: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 15 Mar 2001 05:15:18 +0000
xslt retrive parent element
Hi Ciaran,

> Sorry maybe well-formed was not used in the correct context.

It's just that you're using the term 'well-formed' when you mean
'valid'.

'Well-formed' just means that the start and end tags match and
attributes have quotes around them, that kind of thing - that the XML
follows the XML rules.

'Valid' means that the elements have the right children, parents and
attributes.  Or even if you get into schema validation that their
values are of the right type.

Another option to add to the raft of suggestions for testing whether a
b element is a child of one of a particular set of elements is to
define a key that indexes only those b elements who *are* children of
those elements by their generated id:

<xsl:key name="valid-bs"
         match="p/b | b/b | i/b | u/b | td/b"
         use="generate-id()" />

Since this only matches valid b elements, you can find out whether a b
element is valid by seeing if using the key on its generated ID
actually returns anything:

<xsl:template match="b">
   <xsl:if test="not(key('valid-bs', generate-id()))">...</xsl:if>
   ...
</xsl:template>

Or of course the other thing is that you could just have separate
templates for the two sets of b elements:

<!-- matches valid b elements -->
<xsl:template match="p/b | b/b | i/b | u/b | td/b">
   ...
</xsl:template>

<!-- matches all other b elements -->
<xsl:template match="b">
   ...
</xsl:template>

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 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.