Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: attribute transformation puzzle ( group reference to element - rename attribute and copy it's value )

From: "Joris Gillis" <roac@-------.-->
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)
«Η αλήθεια και το λάδι πάντα βγαίνουν από πάνω»


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent