Subject: RE: Avoiding multiple "apply-templates" by creating one variable for the clauses. Is it possible?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 20 Aug 2009 18:18:28 +0100
|
> > <xsl:apply-templates select="//blog
> > [not($AuthorId) or (author_id = $AuthorId)]
> > [not($CategoryId) or (category_id =
$CategoryId)]
> > "/>
>
> 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)]
> "/>
>
I'm not convinced about this equivalence. If $AuthorId is "Mike", and
author_id is an empty sequence, then
(a) not($AuthorId) or (author_id = $AuthorId) ==> false
(b) not($AuthorId != author_id) ==> true
So if the optimizer does this conversion for you, it's wrong!
But it's probably safe if author_id will always be a singleton node-set.
Regards,
Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay
|