Re: [xsl] priority of key patterns

Subject: Re: [xsl] priority of key patterns
From: Ihe Onwuka <ihe.onwuka@xxxxxxxxx>
Date: Wed, 14 Nov 2012 11:09:32 +0000
On Wed, Nov 14, 2012 at 10:59 AM, Ihe Onwuka <ihe.onwuka@xxxxxxxxx> wrote:
> On Wed, Nov 14, 2012 at 10:44 AM, Andrew Welch <andrew.j.welch@xxxxxxxxx> wrote:
>>>> <xsl:template match="EmployeeCategory | PersonName | FormerlyKnown">
>>>>   <Name>
>>>>
>>>
>>> I cut the examples off with .... too early. Here are a few more
>>> illustrating the more general case for which that solution will not
>>> work.
>>>
>>>  <ren:element from="Directors" to="Names"/>
>>>  <ren:element from="ParentCompany" to="Names"/>
>>>  <ren:element from="LegalStatusAdditional" to="AdditionalInfo"/>
>>>  <ren:element from="EmployeeChanges" to="Changes"/>
>>
>> ...just add more templates!?!
>>
>
> I think it is better to achieve it by adding data (which is what that
> variable is).

and  it is extensible to  attributes at the cost of 1 very similar
template rule.

<xsl:variable name="renames">
   <ren:element from="person" to="individual"/>
   <ren:attribute from="firstname" to="christianname"/>
   <ren:attribute from="lastname" to="surname"/>
</xsl:variable>

<xsl:template match="*[key('mapNames',name(),$renames)]">
    <xsl:element name="{key('mapNames',name(),$renames)[1]}">
        <xsl:apply-templates select="node()|@*/>
    </xsl:element>
</xsl:template>

<xsl:template match="@*[key('mapNames',name(),$renames)]">
    <xsl:attribute name="{key('mapNames',name(),$renames)[1]}">
        <xsl:apply-templates select="node()|@*/>
    </xsl:attribute>
</xsl:template>

Current Thread