At 02:05 PM 01/20/2001 +0800, ÕÅ•F wrote:
> If I have 2 XML Documents which using the smae DTDs. First called
> A, and the other one called B. I want to merge these two documents for
> displaying(such as: xsl, script, vc???):
Well, to merge the documents in general, use one as your normal source tree
and access the other with the XSLT document() function. (See
http://www.w3.org/TR/xslt#document in the XSLT spec for info on
document().) The result tree would then consist of bits of both documents
-- elements copied wholesale, elements from one with attributes from the
other, and so on.
> 1) Don't display the nodes exist in A and not exist in B
Assume that you'll use A as your normal source tree, and make B your other
document. Then you can construct XSLT template rules like:
<!-- Do something with someElem which exists in A
*and* in B -->
Not tested, but that's the general idea. Note that the match expression
does a simple "for someElem in A which exists ANYWHERE in B," which may be
too general. You may/probably have to fine-tune the XPath expression in the
predicate to get the correct, more specific effect.
> 2) For the nodes that exist in both in A and B, reserve some key
> attributes of the nodes in A and update the other attributes with value
> of the nodes in B
To get selected attributes from A, use either xsl:copy-of or xsl:attribute
inside the above template. (If the latter, form its name and values using
those from A.) Then use xsl:attribute to insert attributes and values from B.
> Anoth question is supposing I have the follow xml data structure
> -- root refers to the Document Element
> How to build the XPath Pattern to query the "parent" element
> which childnode - "child" element's value = 2?
Hmm, well, assuming by document element you mean root element, something
like this would work:
The above template rule would process *all* such parent elements; in the
example, there are two of them. Also, rather than use the absolute path
above, for efficiency or other reasons you'd probably want to have separate
template rules for each node, like:
John E. Simpson | "For a while I didn't have a car... I
http://www.flixml.org | had a helicopter... no place to park it,
XML Q&A: www.xml.com | so I just tied it to a lamp post and
| left it running... <slow glance upward>"
| (Steven Wright)