[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: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 25 Sep 2001 16:36:27 -0400
childx
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



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.