RE: [xsl] XPath for matching multiple child elements

Subject: RE: [xsl] XPath for matching multiple child elements
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 29 Sep 2006 08:17:39 +0100
> Probably this would be faster?
> 
> <xsl:stylesheet version="2.0"
>  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>  >
> 
>  <xsl:key name="kComDesc" match="h1|p|b|i"
>    use="exists(ancestor::Comments[1])"/>
> 
>  <xsl:template match="key('kComDesc', 'true')">
>    Whatever processing here
>  </xsl:template>
> </xsl:stylesheet>

Yes, that would probably work reasonably well (and it's nice to find a
plausible use case for using key() in a pattern). One point to be careful
about though: if the "use" value is a boolean, the second parameter of key()
should also be a boolean, so it should be key('kComDesc', true()). There's
no implicit casting in 2.0, and non-comparable values are treated as not
matching, so you can get some hard-to-diagnose errors in this area.

The "[1]" suggests you don't have much confidence in your product's
optimizer...

Michael Kay
http://www.saxonica.com/

Current Thread