[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Comparing nodes minus one child

Subject: Re: Comparing nodes minus one child
From: mjyoungblut@xxxxxxx
Date: Fri, 28 Sep 2001 11:36:47 -0500
childx
Thank you for this help.  It has been very handy.  Now I was wondering I
could get some help on expanding this problem.

Assume that I have two collections of elements <A>(stored in variables)
that I have gotten from two different files.
The collections look something like the following
<HOLDER>
     <A>
          <B>..</B>
          <C>..</C>
          ...
          <X>..</X>
     </A>
</HOLDER>

I want to see if each of the <A> elements in the <HOLDER>(from first
collection) equals an <A> in the <HOLDER>(from the second collection), but
I want the comparison to only include the <A> with all of its children
EXCEPT the <X> element.
My goal is to output the entire <A> element (including the <X> element).

I can get rid of the <X> elements by calling the following templates:
<xsl:template match="node()|@*" mode="remove">
     <xsl:copy>
          <xsl:apply-templates select="node()|@*" mode="remove"/>
     </xsl:copy>
</xsl:template>
<xsl:template match="X"mode="remove">
     <!-- do nothing, we don't want this element in the result -->
</xsl:template>

I know that I can convert each set of <A> elements in both collections to
the compressed version.  Then I would have to iterate through all of the
original <A> elements, compressing that individually, and then comparing it
to the results of the compress second collection. (I also need to do it
going through the second list as well, since I am doing Adds, Deletes,
etc.).  Is there a way to do this more effiently?

Thanks again for your help.
     Matt Youngblut




                                                                                                                   
                    Wendell Piez                                                                                   
                    <wapiez@mulberr      To:     xsl-list@xxxxxxxxxxxxxxxxxxxxxx                                   
                    ytech.com>           cc:     (bcc: Matthew J. Youngblut/US-Corporate/3M/US)                    
                                         Subject:     Re:  Comparing nodes minus one child                    
                    09/25/2001                                                                                     
                    03:36 PM                                                                                       
                    Please respond                                                                                 
                    to xsl-list                                                                                    
                                                                                                                   
                                                                                                                   





Matt:

I assume by "compare" you mean compare their string values. Comparing node
identity is not really practical in XSLT 1.0, nor even called for here.

At 03:37 PM 9/25/01, you wrote:
>     If I have two elements that have the same structure in two
>variables(today_product and yesterday_product):
>      <Product>
>           <Child1>...</Child1>
>           <Child2>...</Child2>
>           ...
>           <ChildX>...</ChildX>
>      </Product>
>
>How can I compare the two <Product> elements by comparing everything but
><ChildX> to see if they are equal?  If possible, I would like to do this
in
>one line as opposed to comparing each part, which I can already do.

You can do it in one line, if you set up some other lines to support your
one-line comparison.... I hope that's good enough.

Basically the trick is to use a mode to load variables with the values you
want; then compare the variables.

For example, you could say

<xsl:variable name="prod-1-value">
   <xsl:apply-templates select="$today-product" mode="product-compare"/>
</xsl:variable>

<xsl:variable name="prod-2-value">
   <xsl:apply-templates select="$yesterday-product" mode
="product-compare"/>
</xsl:variable>

(Note this will only work if $today-product and $yesterday-product are
actually nodes, not RTFs.)

Then have a separate template to say

<xsl:template match="ChildX" mode="product-compare"/>

which will remove the ChildX node from the RTFs created for the variables.
(The others will be included by default.)

Comparing the prod-1-value and prod-2-value RTFs will work as a string
comparison.

If plain string comparison isn't strong enough, you could provide the
strings with pseudo-markup by doing something like

<xsl:template match="*" mode="product-compare">
   <xsl:value-of select="concat('[', local-name(), ']')"/>
   <xsl:apply-templates mode="product-compare"/>
</xsl:template>

which will prefix each element's value with a "tag" (thus making your
string comparison more robust).

If you're curious (and can't already see it in your head), dump the
variables out to look at them before you compare them.

>i.e.  today_product (minus ChildX) ?= yesterday_product (minus ChildX)

I hope that helps.

Cheers,
Wendell



======================================================================
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
======================================================================


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






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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.