Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - attribute transformation puzzle ( group reference to element - rename attribute and copy it's value ) [Thread Next] Re: attribute transformation puzzle ( group reference to element - rename attribute and copy it's value )To: NULL Date: 8/2/2005 8:16:00 AM Hi,
Tempore 01:09:54, die Tuesday 02 August 2005 AD, hinc in foro {microsoft.public.xsl,netscape.public.mozilla.layout.xslt} scripsit Torsten Reichert <TReichert@t...>:
> ==== INPUT =====
> <?xml version="1.0"?>
> <source car_ref_default="http://someurl/standard">
> <car>BMW</car>
> </source>
>
> ==== OUTPUT to be achieved =====
> <?xml version="1.0"?>
> <source car_ref_default="http://someurl/standard">
> <car car_ref=""http://someurl/standard">BMW</car>
> </source>
XML -> XML transformations typically start with an identity transform template.
Another template matches the elements that could receive a pseudo-copy of it's parent attributes:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="node() |@*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="source/*">
<xsl:variable name="rd" select="../@*[contains(name(),'_default')]"/>
<xsl:copy>
<xsl:for-each select="$rd">
<xsl:attribute name="{substring-before(name(.),'_default')}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
«Η αλήθεια και το λάδι πάντα βγαίνουν από πάνω»
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
