Re: [xsl] generating xml from xml

Subject: Re: [xsl] generating xml from xml
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 10 Nov 2003 11:19:09 -0500
Murali,

Keys were invented for just this kind of application.

Declare a key that lets you retrieve your field mapping elements by their id values:

<xsl:key name="field-by-id" match="_" use="@id"/>

Then, for example,

<xsl:template match="Trade/*">
  <xsl:element name="key('field-by-id',local-name())/fn">
    <xsl:apply-templates/>
  </xsl:element>
</xsl:template>

would match a child of Trade and create an element with the appropriate name (if I have it right).

Really, I'm helping you less by writing the code than I would by explaining it better -- but you can (and should) find a good explanation of keys in a published resource.

Whether MSXML3.0 supports keys, I can't say for sure (though I think it does). If not, this can still be done with brute force (albeit expensively) using an XPath location path.

Cheers,
Wendell

At 10:31 AM 11/10/2003, you wrote:
Hi,
I have a situation where I have to apply xsl on some xml and generate slightly different xml. I hope you people can help me.


this is my 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>

and I am trying to generate :


<Data Timestamp="2003-11-05 21:00:07"> <Trades> <Trade> <Level1/> <Level2/> </Trade> <Trade> <Level1/> <Level2>Entry</Level2> <Level3/> </Trade> <Trade> <Level1>Mid</Level1> <Level2/> <Level3/> <TradeDate/> <TradeId>126</TradeId> </Trade> </Trades> </Data>

and my limitation is, the parser I can use should be MSXML3.0 or less.


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


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



Current Thread