[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Comparing nodes minus one child
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> 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|