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

Re: FW: I need help with converting XML document diff

Subject: Re: FW: I need help with converting XML document different formed XML document.
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 30 Jun 2009 12:54:13 -0400
Re:  FW: I need help with converting XML document  diff
At 2009-06-30 12:34 -0400, Johnson, Mike wrote:
I need help with converting XML document to a different formed XML document.
I have looked for examples on how to do this and I'm just not finding what I need.

Rather than copying and pasting, it will help you to understand the process behind the scenes: you are building a new tree from an old tree. The new tree is almost identical to the old tree except for the table data elements.


I'm very new to this

Then you should find a book or online tutorial to understand the basics.


and will continue to look for a solution.

I'm unsure you would find a solution to copy ... it would be best to look at the nature of the problem. You need the identity template for most of the items and you need a template that constructs the result tree as desired for your table data.


If possible can you explain the code.

I've commented the code ... as for explaining it, I'll again suggest you find out how things work rather than simply looking for your exact solution to copy and paste without understanding the principles.


I hope the example below directs you on the principles being used.

. . . . . . . . . . Ken

T:\ftemp>type mike.xml
<?xml  version="1.0" encoding="utf-8"?>

<fxf version="1.0" data="hold">
     <report records="1583" lines="1583" >
         <column_desc>
            <col colnum="c0" fieldname="test"></col>
         </column_desc>
         <table>
             <tr linetype="data" linenum="1">
                 <td colnum="c0">01</td>
                 <td colnum="c1">E1c06</td>
                 <td colnum="c2">40797115201</td>
             </tr>
             <tr linetype="data" linenum="2">
                 <td colnum="c0">02</td>
                 <td colnum="c1">E2c06</td>
                 <td colnum="c2">50797115201</td>
             </tr>

         </table>
      </report>
</fxf>

T:\ftemp>call xslt mike.xml mike.xsl
<?xml version="1.0" encoding="utf-8"?><fxf version="1.0" data="hold">
<report records="1583" lines="1583">
<column_desc>
<col colnum="c0" fieldname="test"/>
</column_desc>
<table>
<item linetype="data" linenum="1" c0="01" c1="E1c06" c2="4079711520
1"/>
<item linetype="data" linenum="2" c0="02" c1="E2c06" c2="5079711520
1"/>


         </table>
      </report>
</fxf>
T:\ftemp>type mike.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

<!--this element is different in the result, so catch and process it-->
<xsl:template match="tr">
  <item>
    <!--the given attributes are preserved-->
    <xsl:copy-of select="@*"/>
    <!--additional attributes are added for each table data element-->
    <xsl:for-each select="td">
      <!--create an attribute out of thin air-->
      <xsl:attribute name="{@colnum}">
        <xsl:value-of select="."/>
      </xsl:attribute>
    </xsl:for-each>
  </item>
</xsl:template>

<xsl:template match="@*|node()"><!--identity for all other nodes-->
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>

T:\ftemp>


i


--
Possible July/August XSLT/XQuery/XSL-FO training in Oakland/CA/USA
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

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.