Subject: Re: [xsl] Template priority query From: "M. David Peterson" <m.david@xxxxxxxxxx> Date: Thu, 10 Jun 2004 06:06:03 -0600 |
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[@length] | b | c"> 1 </xsl:template> <xsl:template match="*[@*]"> 2 </xsl:template> You would probably find yourself scratching your head wondering why you got this output... 2 1 1 >>From this XML... <?xml version="1.0"?> <foo> <a length="1"/> <b/> <c/> </foo> 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 :) http://www.w3.org/TR/xslt#conflict 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... http://www.amazon.com/exec/obidos/tg/detail/-/1861005067/qid=1086868682/sr=1-1/ref=sr_1_1/102-7827557-4096903?v=glance&s=books 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 yet... Best of luck to you! <M:D/> ----- Original Message ----- From: "Chris Loschen" <closchen@xxxxxxxxxxxxxxxxxx> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Sent: Thursday, June 10, 2004 4:53 AM Subject: [xsl] Template priority query > Hi, everybody! > > Quick sanity check -- I've got two templates like this: > > <xsl:template match="a | b | c">...</xsl:template> > > <xsl:template match="*[@length]">...</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! > > > Yours, > > Chris Loschen > closchen@xxxxxxxxxxxxxxxxxx > 781-718-3017 (cell) > > > > --+------------------------------------------------------------------ > 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@xxxxxxxxxxxxxxxxxxxxxx> > --+-- >
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Template priority query, Chris Loschen | Thread | RE: [xsl] tokenize function, David . Pawson |
Re: [xsl] Template priority query, Chris Loschen | Date | error with saxon, sarra hamdi |
Month |