xsl-list
[Top] [All Lists]

RE: how to match the absence of a particular attribute

2005-05-30 07:10:50
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[(_at_)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[(_at_)*]". 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/


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--