xsl-list
[Top] [All Lists]

Re: [xsl] priority of key patterns

2012-11-14 05:09:42
On Wed, Nov 14, 2012 at 10:59 AM, Ihe Onwuka 
<ihe(_dot_)onwuka(_at_)gmail(_dot_)com> wrote:
On Wed, Nov 14, 2012 at 10:44 AM, Andrew Welch 
<andrew(_dot_)j(_dot_)welch(_at_)gmail(_dot_)com> 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>

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>