This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: change a list of attribute name


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.xml:

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

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:if>
       </xsl:for-each>
    </xsl:variable>
    <xsl:attribute name="{$attrName}">
      ...
    </xsl:attribute>
  </xsl:for-each>

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

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]