This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: change a list of attribute name
- To: Xiaocun Xu <xiaocunxu at yahoo dot com>
- Subject: Re: [xsl] change a list of attribute name
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Fri, 3 Aug 2001 18:20:21 +0100
- CC: xsl-list at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <20010803164621.2581.qmail@web11102.mail.yahoo.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
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