At 2007-03-29 10:49 +0200, Abel Braaksma wrote:
Simon Shutter wrote:
Hi Abel,
Sorry for the confusion. I meant only attribute nodes so I assume from your
examples that I have to put the entire path before each attribute of
interest.
Ie // tier1 / tier2 / @attrb1 | // tier1 / tier2 / @attrb2
Is there a way to exclude specific attributes in Xpath 1.0?
Well, like I said, usually the easiest way to do that is by using an
identity transform (see my examples), but I haven't seen your code
so I can't tell it's the right approach.
With any of your XPaths, however, this works for excluding attributes:
//tier1/tier2/@*[not(local-name() = 'exclude-me')]
and this with QNames:
//tier1/tier2/@*[not(name() = 'ns:exclude-me')]
I think someone should make the observation that the above test is
not namespace-safe. There is no obligation that the input instance
use the same namespace prefixes as the stylesheet, so basing the test
on the name of the attribute node is inappropriate.
One could do:
//tier1/tier2/@*[not(local-name()='exclude-me' and
namespace-uri()='...insert URI here ....')]
If you wanted to base the test on the stylesheet use of the "ns"
prefix, one could do:
//tier1/tier2/@*[not(local-name()='exclude-me' and
namespace-uri()=document('')/*/namespace::ns)]
I suppose you could even use the principle of union in:
//tier1/tier2/@*[not(../@ns:exclude-me and
count(.|../@ns:exclude-me)=1)]
Any one of those three above would allow the namespace prefix used in
the input instance for the stylesheet "ns" namespace. I do think
your proffered solution for QNames is not appropriate.
I don't see any problems with the rest of the information in your post.
I hope this is considered helpful.
. . . . . . . . . . . . . . Ken
Finally, you may have hoped this would work, like it does for normal axis:
//tier1/tier2/@*[not(self::exclude-me)]
but then you try to test for the self::node() being an 'exclude-me'
element node, but self::node() is not an element, it is an attribute
(the reason is, technically speaking, that the principal node kind
of self:: is the element node, and you can't switch that).
Unfortunately, XPath does not have a way to express a self::node()
axis when the axis is the attribute axis. I.e., this won't work (illegal):
//tier1/tier2/@*[not(self::@exclude-me)]
XPath 2.0 has a workaround for this (also note the way of using
parenthesis, which is not legal for XPath 1.0, but in this case
saves a lot of re-typing the parent path):
//tier1/tier2/(@* except @exclude-me)
HTH,
-- Abel Braaksma
http://www.nuntia.nl
--
World-wide corporate, govt. & user group XML, XSL and UBL training
RSS feeds: publicly-available developer resources and training
G. Ken Holman mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995)
Male Cancer Awareness Aug'05 http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers: http://www.CraneSoftwrights.com/legal
--~------------------------------------------------------------------
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>
--~--