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

Re: Merging attributes in one XML file with node value

Subject: Re: Merging attributes in one XML file with node values in another (identical structure)
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Fri, 23 Jun 2006 10:06:56 +0530
merge node xml
Here is a Saxon (8.7.3J) specific solution:

file1.xml
------------
<a>
 <b>
    <node>1</node>
 </b>
 <c>
    <d>
       <node>2</node>
    </d>
 </c>
</a>

file2.xml
------------
<a>
 <b val="x">
    <node width="10"/>
 </b>
 <c>
    <d val="z">
       <node height="15"/>
    </d>
 </c>
</a>

merge.xsl
--------------
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                                          xmlns:saxon="http://saxon.sf.net/">

<xsl:output method="xml" indent="yes" />

<xsl:variable name="file2" select="document('file2.xml')" />

   <xsl:template match="*">
        <xsl:copy>
            <xsl:copy-of select="$file2//*[saxon:path() =
current()/saxon:path()]/@*" />
	<xsl:apply-templates />
            </xsl:copy>
   </xsl:template>

</xsl:stylesheet>

java net.sf.saxon.Transform file1.xml merge.xsl
Warning: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor
<?xml version="1.0" encoding="UTF-8"?>
<a>
 <b val="x">
    <node width="10">1</node>
 </b>
 <c>
    <d val="z">
       <node height="15">2</node>
    </d>
 </c>
</a>

Regards,
Mukul

On 6/22/06, Minervini, Chris <christopher.minervini@xxxxxxxxxx> wrote:
O.K. here's my question.  It seems like it should be simple but I can't
figure it out.
I have two XML files. One with data in the node values, and one with
data in attributes. They have the same exact structure.

<a>
  <b>
     <node>1</node>
  </b>
  <c>
     <d>
        <node>2</node>
     </d>
  </c>
</a>

... and ...

<a>
  <b val="x">
     <node width="10"/>
  </b>
  <c>
     <d val="z">
        <node height="15"/>
     </d>
  </c>
</a>

As you can see the word "node" node appears at /a/b/node and a/c/d/node
but has two distinct values and attributes.
Is there a way to transform the first one with XSLT to produce the
following results:

<a>
  <b val="x">
     <node width="10">1</node>
  </b>
  <c>
     <d val="z">
        <node height="15">2</node>
     </d>
  </c>
</a>

...essentially combining the node values of one file with the attributes
in the other.
I've really been struggling with this. I was able to do it with
recursion, but I'm looking for a way to do it without using recursive
procedures. I don't think it's possible. Is it?

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-2011 All Rights Reserved.