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

"Joris Gillis" <[email protected]>
Newsgroups gmane.comp.mozilla.devel.layout.xslt
Organization Telenet Internet
Message-ID <[email protected]>
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 <[email protected]>:

> ==== 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)
«Η αλήθεια και το λάδι πάντα βγαίνουν από πάνω»
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.