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

Subject: Re: [xsl] select elements based on value NOT contained in descendant elements
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Tue, 17 Jul 2007 21:54:12 +0200
cknell@xxxxxxxxxx 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

Current Thread