Re: [xsl] Testing for Parent Nodes of multiple types

Subject: Re: [xsl] Testing for Parent Nodes of multiple types
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 15 Mar 2001 05:15:18 +0000
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