That all depends on what you mean by specific... if you are referring to
the union of the a, b, and c elements then yeah, the first would be more
specific. But the second template matches all elements that have a length
attribute (no matter what the value) where as the first will only match the
a, b, and c elements that don't have an length attribute. If you wanted the
first template to have a higher priority then you need to get very specific
with each element... but that really doesn't explains things very well
either as if you did this...
<xsl:template match="a[(_at_)length] | b | c">
You would probably find yourself scratching your head wondering why you got
From this XML...
So whats the deal? I'm glad you asked :)
There's no better source for the answer than the source from whence all XSLT
1.0 compliant processor developers looked to themselves for guidance in how
they should create the logic for conflict resolution with template rules...
A quick fly-by your browsers rendering of the XSLT 1.0 spec hosted at the
w3.org and wham, bamn, thankyou... James Clark.... and you've got yourself
an answer :)
Enjoy! BTW... if this doesn't help you - and don't feel ashamed if you walk
away from the first pass through more confused than when you came... it can
sometimes take a couple passes through before it begins to sink in...
remember, these specs are written by and for developers who look at compiled
assemblies and find places where they would have optimized things just a bit
differently than the compiler chose to do... Fortunately people like
Michael Kay took pity and gave the rest of us a programmers reference which
at very least gave us a fighting chance - and this is just the person I
would suggest you turn to for deeper guidance (referring to his Wrox
reference of course and not him personally - although I wouldn't be
surprised if you got help directly from him as well... come prepared with
evidence that you've taken the time to really try to figure it out for
yourself first and you might be surprised by the caliber of people you'll
get answers from in here :)
The link to Dr. Kays book on Amazon...
And make sure you get this version which is the second edition of XSLT 1.0
and not the XSLT 2.0 which is available to preorder but isn't being shipped
Best of luck to you!
----- Original Message -----
From: "Chris Loschen" <closchen(_at_)stanfordalumni(_dot_)org>
Sent: Thursday, June 10, 2004 4:53 AM
Subject: [xsl] Template priority query
Quick sanity check -- I've got two templates like this:
<xsl:template match="a | b | c">...</xsl:template>
My assumption has been that the first of these is more specific
and so would have a higher priority than the second, but my output
suggests that the second is firing instead of the first. Is my assumption
faulty, or is something else going wrong? Thanks!
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/