[thelist] setting attribute name with xsl?
Hendrik Schwachenwalde
come2los at yahoo.ca
Mon Jan 24 09:22:07 CST 2005
--- Gavin Montague <gmontague at gmontague.co.uk> wrote:
> Hi all,
>
> I've googled and hit the library but to no avail and
> I'd be grateful if
> any one can shed any light on this.
>
> I have an xml fragment that looks something like....
>
> <metadata>
> <item type="placename" format="name">Glasgow</item>
> <item type="country" format="name">GB</item>
> <item type="telephone"
> format="international_form">+44 141</item>
> </metadata>
>
> to be transformed into
>
> <meta name="placename" content="Glasgow, Scotland"/>
> <meta name="country" content="GB"/>
> <meta international_form="telephone" content="+44
> 141"/>
>
> Not difficult, but what I'd ideally like to do is
> have a general case
> that says, "for each item make the format attribute
> value into the new
> attribute name."
>
> In other words, is it possible to transform a value
> from the source into
> an attribute name in the final document?
>
> Thanks in advance,
> Gav
> --
>
> * * Please support the community that supports you.
> * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip
> Harvester
> and archives of thelist go to:
> http://lists.evolt.org
> Workers of the Web, evolt !
>
try this one:
<xsl:stylesheet version="1.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" media-type="text/xml"
indent="no"/>
<xsl:template match="/">
<xsl:for-each select="$old/metadata/*">
<xsl:call-template name="new-meta">
<xsl:with-param name="type"
select="current()/@type"/>
<xsl:with-param name="format"
select="current()/@format"/>
<xsl:with-param name="content" select="current()"/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="new-meta">
<xsl:param name="type">unknown</xsl:param>
<xsl:param name="format">unknown</xsl:param>
<xsl:param name="content">none</xsl:param>
<meta>
<xsl:attribute name="{$format}"><xsl:value-of
select="$type"/></xsl:attribute>
<xsl:attribute name="content"><xsl:value-of
select="$content"/></xsl:attribute>
</meta>
</xsl:template>
<xsl:variable name="old">
<metadata>
<item type="placename" format="name">Glasgow</item>
<item type="country" format="name">GB</item>
<item type="telephone" format="international_form">+44
141</item>
</metadata>
</xsl:variable>
</xsl:stylesheet>
______________________________________________________________________
Post your free ad now! http://personals.yahoo.ca
More information about the thelist
mailing list