[Home] [By Thread] [By Date] [Recent Entries]
Hi Mark,
Assuming the element names are as given, and that hence each element has a unique name, probably the most straightforward approach would be to key the elements by retrieval using their names. This is largely because your requirements identify two elements as "the same" if they have the same name, and can ignore their positions in the document (at least until it comes to writing your reports). For purposes of exposition, here's an XSLT 2.0 solution: <xsl:key name="element-by-name" match="*" use="name()"/> <xsl:variable name="B" select="document('wheredoyoufind/B.xml')"/> Then you traverse A to report where elements are missing: <xsl:template match="*">
<xsl:if test="empty(key('element-by-name',name(),$B)">
... the element is missing from B ...
</xsl:if>
<xsl:apply-templates/>
</xsl:template>Next to report if values are different. Since you only want to do this on leaf nodes, use a separate template to match only those: <xsl:template match="*[empty(*)]">
<xsl:if test=". != key('element-by-name',name(),$B)">
... A has a different value from B ...
</xsl:if>
<xsl:next-match/>
</xsl:template>The next-match instruction here will (would) then apply the first template also to the elements that match the second one, so its test is also performed. To rewrite this in XSLT 1.0, you have to do two things: * Since key() can't take a third argument to define the scope of retrieval, you have to work extra to use the key on document B. So: <xsl:template match="*">
<xsl:variable name="n" select="name()"/>
<xsl:for-each select="$B">
<xsl:if test="not(key('element-by-name',$n)">
... the element is missing from B ...
</xsl:if>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:template>Do similarly for the other template. * Since xsl:next-match is not available in XSLT 1.0, work around this by giving the template matching * a name, which you can call (by name) from the other template. I hope this helps. Cheers, Wendell On 1/20/2012 1:57 PM, Mark Anderson wrote: Hi Guys -- ====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
|

Cart



