RE: [xsl] how to match the absence of a particular attribute

Subject: RE: [xsl] how to match the absence of a particular attribute
From: "Aron Bock" <aronbock@xxxxxxxxxxx>
Date: Mon, 30 May 2005 14:10:50 +0000
how can I test the presence of a particular attribute of a node in an
"if" or "choose" tag?
I need to drive the behavior of the translation in two different ways,
if an attribute exists or not.

Given:


<A>
  <B a="a">hello2</B>
  <B a="a" b="b">hello3</B>
  <B>hello1</B>
  <B b="b">hello4</B>
</A>

If you want only those Bs which have a or b attributes, the following witll pick them out:

<xsl:template match="A/B[@a or @b]">
   <xsl:copy-of select="."/>
</xsl:template>

If you want only those Bs which have at least one attribute, the expression would be select="A/B[@*]". If you want only those Bs which have no "a" attribute, the expression would be select="A/B[not(@a)]", and so forth.

I suppose the key point is the
capability to match the absence of an attribute, but I have found no
way to do this.

As advice I should follow myself, if you haven't formally read any books on XML/XSLT, doing so would be of huge benefit.


Regards,

--A

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


Current Thread