[Home] [By Thread] [By Date] [Recent Entries]
Chris,
The hard part of this problem is identifying which node in your second document is the "same" node as a given node in your first document. This is much easier if you can pre-process one or both documents (pipeline). The first pass could label the nodes in one of the documents to allow them to be looked up in the merge pass. If it were me, I'd probably label them with an XPath to identify each node uniquely (partly since I've done this before and know how :-). Using this approach, a simple labeling stylesheet would look like this: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:attribute name="xpath">
<!-- assuming your input doesn't already have 'xpath' attributes -->
<xsl:for-each select="ancestor-or-self::*">
<xsl:text>/</xsl:text>
<xsl:value-of select="name()"/>
<xsl:if test="count(../*[name()=name(current())]) > 1">
<xsl:text>[</xsl:text>
<xsl:number/>
<xsl:text>]</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:attribute>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template></xsl:stylesheet> Run this over your input documents and the results will be much easier to merge. In the second phase, I'd probably write a key to retrieve my nodes efficiently using their @xpath values. In XSLT 2.0 you could do this in a single stylesheet. I hope that helps, Wendell At 09:59 AM 6/22/2006, you 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.
|

Cart



