Subject: Re: priority of key patterns
From: Andrew Welch <andrew.j.welch@xxxxxxxxx>
Date: Wed, 14 Nov 2012 10:24:22 +0000
|
> Regarding other use cases for keys in patterns - I tend to do my
> renames like this
>
> <xsl:key name="mapNames" match="ren:*/@to" use="../@from"/>
> <xsl:variable name="renames">
> <ren:element from="EmployeeCategory" to="Name"/>
> <ren:element from="PersonName" to="Name"/>
> <ren:element from="FormerlyKnown" to="Name"/>
I would just do:
<xsl:template match="EmployeeCategory | PersonName | FormerlyKnown">
<Name>
Also top tip regarding this:
>>> <xsl:apply-templates select="node()|@*"/>
What the union operator | does is de-dupe and sort the nodes into
document order, so by doing "node() | @*" you are giving the processor
more work than "@* | node()" because all the attributes nodes have to
be moved in the sort before the node()s.
If you are using xslt 2.0, then you should use "@*, node()" (comma
instead of pipe) which returns the nodes exactly the way you specify,
without the de-dupe or sort.
As an example, try
"node() | @*"
vs
"node(), @*"
and
"@* | node() | node()"
vs
"@*, node(), node()"
--
Andrew Welch
http://andrewjwelch.com
|