xsl-list
[Top] [All Lists]

Re: [xsl] select elements based on value NOT contained in descendant elements

2007-07-17 13:17:45
Thanks. In the words of that international TV star (and soon to be the star of 
a feature film, Homer J. Simpson, "Doh!")

(Those of you who are not U.S. residents please forgive me if the reference is 
too parochial, but I have been led to believe that The Simpsons has been widely 
syndicated outside North America.)

I wasn't the whitespace.

The original file is flat, as in:

<ROWSET>
  <ROW>
    <NAME/>
    <CREDIT_CARD/>
    <ISSUER/>
    <NUMBER/>
  </ROW>
  <ROW>
    <NAME/>
    <CREDIT_CARD/>
    <ISSUER/>
    <NUMBER/>
  </ROW>
  <ROW>
    <NAME/>
    <CREDIT_CARD/>
    <ISSUER/>
    <NUMBER/>
  </ROW>
</ROWSET>

And I was using xsl:for-each-group to create a single elment for each <NAME> 
and group all credit cards issued to that <NAME> in the fashion outlined in my 
original post.

I suppose I was getting ahead of myself by assuming the existence of the new, 
grouped document at the same time I was creating it. Of course, now this is 
obviously wrong, but I've only just now seen it.

I'll just move the filtering further down the pipeline.


Thanks again.
-- 
Charles Knell
cknell(_at_)onebox(_dot_)com - email



-----Original Message-----
From:     Abel Braaksma <abel(_dot_)online(_at_)xs4all(_dot_)nl>
Sent:     Tue, 17 Jul 2007 21:54:12 +0200
To:       xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject:  Re: [xsl] select elements based on value NOT contained in descendant 
elements

cknell(_at_)onebox(_dot_)com wrote:
Consider this structure:
<ROWSET>
<ROW>
  <NAME/>
  <CREDIT_CARDS>
    <CREDIT_CARD>
       <ISSUER/>
       <NUMBER/>
    </CREDIT_CARD>
    <CREDIT_CARD>
       <ISSUER/>
       <NUMBER/>
    </CREDIT_CARD>
  </CREDIT_CARDS>
</ROW>
</ROWSET>

I need to select the rows who do not have a CREDIT_CARD descendant whose 
ISSUER descendant contains one of a set of values.

For example, say that I want to select all ROW elements that do not have an 
ISSUER descendant with one of these values: ABC, MNO, RST


I tried a construct like this, but it failed to filter out the ROWS I 
expected it to filter,

select="ROW[not(CREDIT_CARDS/CREDIT_CARD/ISSUER= ('ABC','MNO','RST'))]"

Namely, ROW elements which had ISSUER descendants whose text value was one of 
the three listed strings.

What am I missing here? Am I misusing the not() operator?
  

Your construct seems correct (at first sight). But how do you ISSUER 
elements look like? You compare the string values. Do you consider 
space? I.e., if your ISSUER looks like this:

<ISSUE>
   ABC
</ISSUE>

it will not be considered as in that list. Likewise, if you are mistaken 
about the path (I can't check, you did not provide the original source), 
which you can easily find out by doing:

<xsl:value-of select="ROW/CREDIT_CARDS/CREDIT_CARD/ISSUER" separator="," />

if that returns nothing, you have a mistake in your path.

If the whitespace is the problem, you can fix is, for instance, like this:

ROW[not(CREDIT_CARDS/CREDIT_CARD/ISSUER/normalize-space() = 
('ABC','MNO','RST'))]


HTH,
Cheers,
-- Abel Braaksma

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>