[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Avoiding multiple "apply-templates" by creating on
At 2009-08-20 15:20 +0100, Kate Busch-Petersen wrote:
Brilliant! That's exactly what I'm looking for. I guess I'll finally drop in and add another suggestion since I've been waiting for one of my XSLT students to bring it up but I don't see any of them doing so. If you are looking for compactness, I believe the above expression can be reduced to the following in both XSLT 1.0 and XSLT 2.0: <xsl:apply-templates select="//blog [not($AuthorId != author_id)] [not($CategoryId != $CategoryId)] "/> Whether the processor optimizes your expression to the above expression is up to the processor, but the above does only one comparison per predicate not two, so for some processors my suggestion may in fact be executed more quickly. There are many cases in my OASIS code list work where I use this "not(x!=y)" idiom very successfully. The principle I bring up in class is that a node set comparison with an empty node set operand returns false. If it is not empty all members are tested with the other operand until a true is found, otherwise a false is returned when all tests are exhausted. So if there is no AuthorId, then the blog element is selected because the node set is empty making the inside of the not() false and the outside of not() true. If there is an AuthorId and it is equal to author_id, the inside of not() is false, so the outside of not() is true, and the blog element is selected. But if there is an AuthorId and it is not equal to author_id, the inside of not() is true, so the outside of not() is false, and the blog element is not selected. I hope this is considered helpful and not critical of your work. . . . . . . . . . . . Ken
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|