[xsl] Comparison of nodes minus a child node

Subject: [xsl] Comparison of nodes minus a child node
From: mjyoungblut@xxxxxxx
Date: Tue, 30 Oct 2001 16:37:20 -0600
I have two sets of elements
<ListofHierarchies>
     <Hierarchy>
          <Child1>...</Child1>
          <Child2>...</Child1>
          ...
          <Child7>...</Child7>
     </Hierarchy>
</ListofHierarchies>

I want to compare these two ListofHierarchies, but I don't want to include
<Child7> in the comparison.  Here is the XSL that I currently use.  It
produces the results that I desire, but it is slow, even if the Hierarcy
elements are the same between the two sets.  The test that I am running has
about 80,000 hierarchy elements.  If I run the whole XSL with the following
snippet included, it takes 16 minutes; with the snipped commented out, it
takes about 2 minutes.  So this is definitely what is holding me back.

Does anybody have another solution to take out the <Child7> element, and
compare the Hierarchy elements in a faster way?

<xsl:if test="$TODAY_PROD//ListofHierarchies or
$YEST_PROD//ListofHierarchies">
     <xsl:variable name="TODAY_HIERS"><xsl:apply-templates select
="$TODAY_PROD//ListofHierarchies//Hierarchy"
                                              mode
="hierarchy"><xsl:sort/></xsl:apply-templates></xsl:variable>
     <xsl:variable name="YEST_HIERS"><xsl:apply-templates select
="$YEST_PROD//ListofHierarchies//Hierarchy"
                                              mode
="hierarchy"><xsl:sort/></xsl:apply-templates></xsl:variable>
     <xsl:if test="not($TODAY_HIERS=$YEST_HIERS)">
          <ListofHierarchies>
               <xsl:for-each select
="$TODAY_PROD//ListofHierarchies//Hierarchy">
                    <xsl:variable name="IND_TODAY"><xsl:apply-templates
select="." mode="hierarchy"/></xsl:variable>
                    <xsl:if test="not($IND_TODAY
= $YEST_HIERS//Hierarchy)">   <!-- Hierarchy is an Add -->
                         <xsl:copy-of select = "."/>
                    </xsl:if>
               </xsl:for-each>
               <xsl:for-each select
="$YEST_PROD//ListofHierarchies//Hierarchy">
                    <xsl:variable name="IND_YEST"><xsl:apply-templates
select="." mode="hierarchy"/></xsl:variable>
                    <xsl:if test="not($IND_YEST
= $TODAY_HIERS//Hierarchy)">
                         <xsl:apply-templates select="." mode="delete"/>
                    </xsl:if>
               </xsl:for-each>
          </ListofHierarchies>
     </xsl:if>
</xsl:if>

<xsl:template match="node()|@*" mode
="delete"><xsl:copy><xsl:apply-templates select="node()|@*" mode
="delete"/></xsl:copy></xsl:template>
<xsl:template match="@Action" mode="delete"><xsl:attribute name
="Action">D</xsl:attribute></xsl:template>

<xsl:template match="node()|@*" mode
="hierarchy"><xsl:copy><xsl:apply-templates select="node()|@*" mode
="hierarchy"/></xsl:copy></xsl:template>
<xsl:template match="HierarchyDotNotation" mode="hierarchy"/>

Thank you in advance,
     Matt Youngblut




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread