[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
On 14/11/2012 06:51, Ihe Onwuka wrote:
(I say "almost equivalent", because it's not quite the same as two separate rules: the effect of xsl:next-match is different).
Incidentally, I very rarely see key() used in patterns. I'd be interested to know the use case. In XSLT 3.0 we're allowing a variable reference as a pattern, so you can do for example
<xsl:variable name="oddities" select="//w:X[preceding-sibling::*[1][self::w:Y[w:Z]]]">
<xsl:template match="$oddities">...</xsl:template>
and I've seen key() patterns used for this kind of use case in 1.0 and 2.0 - the actual key is generally immaterial.
Re: [xsl] priority of key patterns
Subject: Re: [xsl] priority of key patterns From: Michael Kay <mike@xxxxxxxxxxxx> Date: Wed, 14 Nov 2012 08:48:58 +0000 |
On 14/11/2012 06:51, Ihe Onwuka wrote:
Yes (the spec is fairly clear, I think).Would I be right in concluding that the default priority of the first template below that features a call to a key function in the match pattern is 0.5.
Your second template rule is rather peculiar, because the first alternative (*) embraces the second (Payloadfile); except that they have different priorities, so this is almost equivalent to writing a match="*" template with priority -0.5, and a match=Payloadfile template with priority 0. Unless there's another template rule with intervening priority, the second half of the union is pointless.
<xsl:template match="key('privateData','private')" priority="-0.1"> <private oldName="{local-name()}"> <xsl:apply-templates select="node()|@*"/> </private> </xsl:template>
<xsl:template match="*|PayloadFile"> <xsl:element name="{local-name()}"> <xsl:apply-templates select="node()|@*"/> </xsl:element>
(I say "almost equivalent", because it's not quite the same as two separate rules: the effect of xsl:next-match is different).
Fine. So? That's what priorities are for.I found myself having to override the priority in order to ensure that the PayloadFile element (otherwise caught by the key) would be processed by the 2nd template rule.
Incidentally, I very rarely see key() used in patterns. I'd be interested to know the use case. In XSLT 3.0 we're allowing a variable reference as a pattern, so you can do for example
<xsl:variable name="oddities" select="//w:X[preceding-sibling::*[1][self::w:Y[w:Z]]]">
<xsl:template match="$oddities">...</xsl:template>
and I've seen key() patterns used for this kind of use case in 1.0 and 2.0 - the actual key is generally immaterial.
Yes. Patterns become less restrictive in XSLT 3.0. Unfortunately this makes the default priority rules even more complicated.
On an unrelated note not worth starting a new thread, I tried using except in an xsl:key match clause - which was rejected. I presume it is one of those pattern rules that I keep falling foul of (XSLT 2.0).
Michael Kay Saxonica
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] priority of key patterns, Ihe Onwuka | Thread | Re: [xsl] priority of key patterns, Ihe Onwuka |
[xsl] priority of key patterns, Ihe Onwuka | Date | Re: [xsl] priority of key patterns, Ihe Onwuka |
Month |
Keywords