Xpathforlife
Xpathforlife

Reputation: 87

select multiple attribute values in xslt

When I try to write a template with match I am not getting correct results.

Input :

<row>
   <entry align="left" nameend="8" namest="1" valign="top">
      <p type="Table Title">TABLE 12.  ELECTRICITY GENERATION
         (BILLION kW<tps:c type="_Table Light Blue grid ALL">·</c>h) IN ALTERNATIVE
      SCENARIOS</p>
   </tps:entry>
   <entry align="left" nameend="8" namest="1" valign="top">
      <p type="Table Title">TABLE 12.  ELECTRICITY GENERATION
         (BILLION kW<tps:c type="_Table Blue grid ALL">·</c>h) IN ALTERNATIVE
      SCENARIOS</p>
   </tps:entry>
</row>

Used code :

<xsl:template match="entry/p/c[@type != ('_Table Blue grid ALL' , '_Table Light Blue grid ALL' , '_Table Light Blue')]

I want to select c nodes where mentioned attribute values don't contain(not equal). But every c nodes are selected when I used Used code. How can I resolve this.

Upvotes: 2

Views: 41

Answers (1)

Tim C
Tim C

Reputation: 70608

You current expression will return true if the c value is not equal to just one of the selected values, not all of them, so effectively it will always be true.

You want to do this..

<xsl:template match="entry/p/c[not(@type = ('_Table Blue grid ALL' , '_Table Light Blue grid ALL' , '_Table Light Blue'))]" />

Do note this assumes you accounted for namespaces (with xpath-default-namespace perhaps)?

Upvotes: 1

Related Questions