Re: [xsl] change a list of attribute name

Subject: Re: [xsl] change a list of attribute name
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Fri, 3 Aug 2001 18:20:21 +0100
Hi Xiaocun,

> I failed to show the more complicated case where "Organization
> Unique ID" need to be transformed into "OrganizationCode". There
> isn't a set rule to transform from one to another. So I am looking
> for a more general solution where one set of values can be mapped to
> another set.

Oh right. I was confused by the fact that you said you were
*generating* the node set of new node names - I thought you meant that
you were generating the new node names on the fly, not that they were
static. In that case I'd probably use a document holding the mapping
information for those that had non-standard maps, have something like

  <map value="Organization Unique ID" name="OrganizationCode" />

Hold that document in a variable:

<xsl:variable name="maps" select="document('map.xml')" />

Define a key that indexed the names by the values that should be
converted into those names:

<xsl:key name="maps" match="map/@name" use="../@value" />

And then do something similar to what I said before:

  <xsl:for-each select="$header/cell">
    <xsl:variable name="value" select="." />
    <xsl:variable name="attrName">
       <xsl:for-each select="$maps">
         <xsl:variable name="mapName" select="key('maps', $value)" />
         <xsl:value-of select="$mapName" />
         <xsl:if test="not($mapName)">
           <xsl:value-of select="translate($value, ' ', '')" />
    <xsl:attribute name="{$attrName}">

There's no need to use a node-set() extension function if you access
the information about the non-standard names using the document()


Jeni Tennison

 XSL-List info and archive:

Current Thread