Subject: Re: [xsl] 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 |
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:template match="*"> <xsl:copy> <xsl:copy-of select="$file2//*[saxon:path() = current()/saxon:path()]/@*" /> <xsl:apply-templates /> </xsl:copy> </xsl:template>
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
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] RE : Re: [xsl] RE : Re: [xsl], Florent Georges | Thread | [xsl] Finding the first among equal, Peter Riocreux |
RE: [xsl] Converting CSV to XML wit, Pantvaidya, Vishwaji | Date | Re: [xsl] Merging attributes in one, Dimitre Novatchev |
Month |