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

RE: generating xml from xml

Subject: RE: generating xml from xml
From: "Murali Korrapati" <murali.korrapati@xxxxxxxxx>
Date: Mon, 10 Nov 2003 14:27:12 -0500
murali korrapati
Sure, "Trade/*" is just a guess at an appropriate match pattern based on 
the input sample you sent. You can match the elements any way that works 
for your data. (You only need a way to distinguish between elements that 
you want handled like this, and other elements.)

 Thanks for the solution. But I am not really good in this xsl. Solution to this problem will be helpful.

Here is my current xsl that works fine for me. 

<xsl:stylesheet version="1.0" xmlns="" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="/">
		<xsl:apply-templates select="*"/>
	</xsl:template>
	<xsl:template match="*">
		<xsl:copy>
			<xsl:apply-templates select="@* | node()"/>
		</xsl:copy>
	</xsl:template>
	<xsl:template match="Trade">
		<Trade>
			<xsl:for-each select="*">
				<xsl:element name="{/Data/Fields/_[@id=name(current())]/@fn}">
					<xsl:apply-templates select="@* | node()"/>
				</xsl:element>
			</xsl:for-each>
		</Trade>
	</xsl:template>
	<xsl:template match="@* | node()">
		<xsl:copy>
			<xsl:apply-templates select="@* | node()"/>
		</xsl:copy>
	</xsl:template>
</xsl:stylesheet>

which works great on this xml :

<Data Timestamp="2003-11-05 21:00:07">
	<Fields>
		<_ fn="Level1" id="F0"/>
		<_ fn="Level2" id="F1"/>
		<_ fn="Level3" id="F2"/>
		<_ fn="TradeDate" id="F3"/>
		<_ fn="TradeId" id="F4"/>
		<_ fn="User" id="F5"/>
	</Fields>
	<Trades>
		<Trade>
			<F0/>
			<F1/>
		</Trade>
		<Trade>
			<F0/>
			<F1>Entry</F1>
			<F2/>
		</Trade>
		<Trade>
			<F0>Mid</F0>
			<F1/>
			<F2/>
			<F3/>
			<F4>126</F4>
		</Trade>
	</Trades>
</Data>

But I want it to work on this kind of xml also

<Data Timestamp="2003-11-05 21:00:07">
	<Fields>
		<_ fn="Level1" id="F0"/>
		<_ fn="Level2" id="F1"/>
		<_ fn="Level3" id="F2"/>
		<_ fn="TradeDate" id="F3"/>
		<_ fn="TradeId" id="F4"/>
		<_ fn="User" id="F5"/>
	</Fields>
	<Trades>
		<Trade>
			<F0/>
			<F1>Entry</F1>
			<F2/>
		</Trade>
		<Trade>
			<F0>Mid</F0>
			<F1/>
			<F2/>
			<F3/>
			<F4>126</F4>
		</Trade>
	</Trades>
	<DelTrades>
		<DelTrade>
			<F0/>
			<F1/>
		</DelTrade>
	</DelTrades>
</Data>

Notice that top nodes(Trade, DelTrade) on F0, F1 ..... are not same all the time. And I can't guarantee their names at run time. 
Is there any way directly(not depending on its top node) finding nodes F0, F1, F2 .......?

Thanks,
~Mur

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.