xsl-list
[Top] [All Lists]

Re: Help comparing an attribute to a Node-Set

2004-09-18 16:01:18
This is a FAQ. 

   $value != $nodeSet 

returns true if there's at least one node in $nodeSet whose value is
not equal to $value.

Even if there is some node in $nodeSet whose value is equal to $value,
there would be typically many other nodes with different values, so
the comparison above would be true.

This is not what you want (and in fact Michael Kay warns strongly
against using the != operator in his book).

Therefore, use:

     not( $value = $nodeSet )

This returns true if there isn't any node in $nodeSet whose value is
equal to $value.


Cheers,

Dimitre Novatchev


On Sat, 18 Sep 2004 12:42:20 -0700 (PDT), Charlie Consumer
<faceless1976(_at_)yahoo(_dot_)com> wrote:
Hi,

I have a question about comparing a single attribute
to a set of nodes.  I'm trying to remove any XML
elements where their @GUID attribute is equal to one
of the GUIDs (guid0 or guid1) in another document.
The comparison I'm doing right now always returns true
which causes all the the nodes to be added.  I want to
only add the elements in the source XML whose GUID's
are not in the other document either guid0 or guid1.
Without posting the entire document here is my some
excerts I'm using right now:

<xsl:template match="Rule">
 <xsl:if test="@GUID!=member/@guid0 and
@GUID!=member/@guid1">
 <xsl:element name="{name(.)}" >
     <xsl:copy-of select="@*"/>
     <xsl:apply-templates/>
   </xsl:element>
 </xsl:if>
</xsl:template>

The source to the XSL is:

<Rule GUID="zzzzzzzzzz" Enabled="true"
Action="Allow"/>
<Rule GUID="yyyyyyyyyy" Enabled="true" Action="Deny"/>
<Rule GUID="wwwwwwwwww" Enabled="true"
Action="Allow"/>

The other document XML is:

<member guid0="aaaaaaaaaa" guid1="yyyyyyyyyy"/>
<member guid0="zzzzzzzzzz" guid1="xxxxxxxxxx"/>
<member guid0="bbbbbbbbbb" guid1="cccccccccc"/>

The expected result would be:

<Rule GUID="wwwwwwwwww" Enabled="true"
Action="Allow"/>

Any ideas what I'm doing wrong?

Thanks
Charlie

__________________________________
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.
http://promotions.yahoo.com/new_mail

--+------------------------------------------------------------------
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>