[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Reading two xmls and changing the attribute names

Subject: Re: Reading two xmls and changing the attribute names in the first xml conditionally
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Wed, 06 Jul 2005 11:05:35 +0200
reading xsl attribute
Hi,

Tempore 10:34:27, die 07/06/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Lakshmi narayana <lchintala@xxxxxxxxxxxx>:

6) Can any one send me the xsl code for this scenario.
consider that the scond file is named 'second.xml' and the stylesheet is processed on the first file.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="xml"/>


<xsl:key name="newName" match="destination" use="concat(local-name(../..),../source/@name)"/>

<xsl:template match="node()">
	<xsl:copy>
		<xsl:apply-templates select="@*">
			<xsl:with-param name="Type" select="@Type"/>
		</xsl:apply-templates>
		<xsl:apply-templates select="node()"/>
	</xsl:copy>
</xsl:template>
	
<xsl:template match="@*">
<xsl:param name="Type"/>
<xsl:variable name="name" select="local-name()"/>
<xsl:variable name="newname">
	<xsl:for-each select="document('second.xml')">
		<xsl:value-of select="key('newName',concat($Type,$name))/@name"/>
	</xsl:for-each>
</xsl:variable>
<xsl:attribute name="{$newname}"><xsl:value-of select="."/></xsl:attribute>
</xsl:template>

<xsl:template match="@Type"><xsl:copy/></xsl:template>

</xsl:stylesheet>


will produce:


<A1 A-Element-Name="A1" A-sequence="1" A-Description="optional" Type="AGroup">
<B1 B-Element-Name="B1" B-sequence="101" B-order="first" Type="BGroup"/>
<B2>
<C1 C-Element-Name="C1" C-sequence="201" C-order="Sec" Type="CGroup"/>
<C2 C-Element-Name="C2" C-sequence="202" C-order="Sec" Type="CGroup">
<C3/>
<D1 D-Element-Name="D1" D-Min="1" D-Max="1" D-Reference="Trr" D-Predicate="" Type="DGroup">
<C2 C-Element-Name="C2" C-sequence="202" C-order="Sec" Type="CGroup"/>
</D1>
</C2>
</B2>
</A1>



regards, -- Joris Gillis (http://users.telenet.be/root-jg/me.html) Spread the wiki (http://www.wikipedia.org)

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.