Re: [xsl] URGENT:Ignore Tags

Subject: Re: [xsl] URGENT:Ignore Tags
From: Matt Gushee <mgushee@xxxxxxxxxxxxx>
Date: Tue, 26 Feb 2002 12:51:56 -0700
On Tue, Feb 26, 2002 at 07:43:00PM -0000, vasu   deva wrote:

> <root>
>  <child id = '1'>happy</child>
>  <child id = '2'>happy</child>
>  <child id = '3'>happy</child>
>  <child id = '1'>sad</child>
>  <child id = '2'>sad</child>
>  <child id = '3'>sad</child>
> </root>

Oh boy. First of all, this is bad XML (explanation below). If you
have control over the source documents, you should change them. If
not, you should try to persuade whoever does have control to change.
But of course, I know that sometimes us developers have to deal
with other people's bad XML, and there's not always an alternative.

It's bad XML because the value of an ID attribute (i.e., one, with a 
data type of ID) must be unique within each document. Furthermore,
the value must start with a name-start character (in English, that's
letters of the alphabet plus '_'). Now, the XML spec doesn't require
that an attribute named 'id' to have a type of ID. But for reasons
that should be obvious, it's a good idea to only use the name 'id'
for attributes that really are IDs.

With that rant out of the way, this XPath expression

   "child[@id != preceding-sibling::*/@id]"
should do what you want. Or if the important issue is the string
value 'happy', and you don't really care about the IDs, you could

   "child[normalize-space() = 'happy']"

Matt Gushee
Englewood, Colorado, USA

 XSL-List info and archive:

Current Thread