xsl-list
[Top] [All Lists]

RE: [xsl] merge/join two xml files.

2006-11-27 18:05:33
Sorry Michael, 
I still can not make it working. Here are the details
of my two Xml files.  

1. A.xml
"
<?xml version="1.0" encoding="ISO-8859-1" ?>
<?xml-stylesheet href="test.xsl" type="text/xsl"?>
<suites>
    <suite thread-count="5" verbose="2"
name="WandSpecial" parallel="null" annotations="JDK5">
        <test
name="test.domain.billing.PurchaseOrderTest"
junit="true">
             <completed>OK</completed>
             <total>10</total>
             <passed>3</passed>
             <failed>7</failed>
             <skipped>0</skipped>
        </test>
        <test
name="test.domain.billing.TravelExpenseTest"
junit="true">
             <completed>OK</completed>
             <total>15</total>
             <passed>10</passed>
             <failed>2</failed>
             <skipped>3</skipped>
        </test>
     </suite>
</suites>
", 

2. B.xml 
" 
<?xml version="1.0" encoding="ISO-8859-1" ?>
<?xml-stylesheet href="test.xsl" type="text/xsl"?>
<suites>
    <suite thread-count="5" verbose="2"
name="WandSpecial" parallel="null" annotations="JDK5">
        <test
name="test.domain.billing.PurchaseOrderTest"
junit="true">
             <completed>OK</completed>
             <total>10</total>
             <passed>10</passed>
             <failed>0</failed>
             <skipped>0</skipped>
        </test>
     </suite>
</suites>
"

thanks a lot !

chun 


--- Michael Kay <mike(_at_)saxonica(_dot_)com> wrote:

It depends on many details that you haven't
supplied, but let's assume 

(1) apart from the handling of X, the rest of the
transformation is copying
A.xml unchanged.

(2) the element that might or might not contain an X
child is called P, and
this is the only P element in the document, and the
X element from B.xml is
to be added as the last child of P.

Then with A as the principal input document do:

<xsl:template match="*">
  <xsl:copy>
  <xsl:copy-of select="@*"/>
  <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

<xsl:template match="P[not(X)]">
  <xsl:copy>
  <xsl:copy-of select="@*"/>
  <xsl:apply-templates/>
  <xsl:copy-of select="document('B.xml')//X"/>
  </xsl:copy>  
</xsl:template>

Michael Kay
http://www.saxonica.com/
   

-----Original Message-----
From: chun ji [mailto:cji_work(_at_)yahoo(_dot_)com] 
Sent: 27 November 2006 20:56
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] merge/join two xml files. 

(Sorry if this quiestion have been asked before,
cause I just 
joined this group 5 minutes ago. ) 

I have two files, A.xml and B.xml. Both files have
the same root. 
File A might or might not have node X(and its sub
elements).
File B will always have node X(and its sub
elements).

If File A does not contain node X, XSLT should get
it from 
file B and insert it in File A under the defined
location.
 
If File A contains node X (the location is known),
XSLT 
should still get it from file B and replace the
one existed in File A.

Does someone know how to make it happen by XSLT ? 


Thanks a lot !


Chun 




 


______________________________________________________________
______________________
Cheap talk?
Check out Yahoo! Messenger's low PC-to-Phone call
rates.
http://voice.yahoo.com



--~------------------------------------------------------------------
XSL-List info and archive: 
http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to:
http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive: 
http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to:
http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





 
____________________________________________________________________________________
Yahoo! Music Unlimited
Access over 1 million songs.
http://music.yahoo.com/unlimited

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--