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

Re: XSLT Subtract function?

Subject: Re: XSLT Subtract function?
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Fri, 13 Apr 2007 08:43:48 -0700
Re:  XSLT Subtract function?
Do have a look at the

filter()

functio in FXSL.



--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play






On 4/13/07, cknell@xxxxxxxxxx <cknell@xxxxxxxxxx> wrote:
Yesterday I was tasked to produce a list of records from an Oracle database where the result set contained rows where the value in one of the columns was not one of a long list. (Bear with me, please, we'll get to XSLT in a moment.)

The problem was that the list of values to omit was simply too long for SQL*Plus. So I went to plan B. I selected all the rows from the table in question into an XML document. I prepared a second XML document that contained an element for each of the values to be omitted.

I then wrote a stylesheet with this template:

<xsl:template match="ROWSET">
 <ROWSET>
   <xsl:apply-templates select="ROW[not(CODE = $active-codes/ROWSET/ROW/CODE)]" />
 </ROWSET>
</xsl:template>

So the output contained all the ROW elements in the original document whose CODE child string value didn't match any of the CODE string values in the document containing the values I wanted to omit from the result.

In short, I wanted to subtract the set of values contained in the second document from the first, resulting in a document containing only the non-matching values.

After I finished, it occurred to me that this probably wasn't so unusual a need, and that probably someone had written a general-purpose function for this. What I had in mind is a function that would take four arguments:

1) A base document (base document) [$base]
2) A document containing the values to subtract from the base document (exemplar document) [$exemplar]
3) The XPath to the elment in the base document holding the values of interest. [$base-element]
4) The XPath to the element in the exemplar document holding the values of interest. [$list-element]

The result would be a document with the same structure as the base document containing only those elements which didn't have a matching value.

Here is an example of two documents:

The base document:

<?xml version="1.0"?>
<grocery-list>
 <item>apple</item>
 <item>milk</item>
 <item>cheese</item>
 <item>coffee</item>
 <item>asparagus</item>
</grocery-list>

The exemplar document:

<?xml version="1.0"?>
<inventory>
 <sku>apple</sku>
 <sku>pear</sku>
 <sku>grapes</sku>
</inventory>

What I would like is a general-purpose function that would subtract those elements from the first document whose values matched the elements in the second.

<grocery-list>
 <item>milk</item>
 <item>cheese</item>
 <item>coffee</item>
 <item>asparagus</item>
</grocery-list>

I've poked around on Google, but haven't found a useful was to compose the search. Does anyone on the list know of such a function or have you written one? I am reluctant to re-invent the wheel, particularly when mine is not likely to be as round and smooth as an existing one.

Thanks.

--
Charles Knell
cknell@xxxxxxxxxx - email

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-2011 All Rights Reserved.