Dymond
Dymond

Reputation: 2277

Select elements with values smaller than some number

With this line I can print out values that are bigger than 1999

 <xsl:for-each select="//ad[regyear >= 1999]" >

But I cant seem to find out how to print out values from 1998 and down.

Upvotes: 1

Views: 73

Answers (3)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243519

For readability I recommend not to use &lt;.

Instead of:

//ad[regyear &lt;= 1998] 

I use:

//ad[not(regyear > 1998)] 

Never escape the > char in an XPath expression -- I am not aware of a case when this is necessary.

Finally, as Lars correctly mentions, in XPath 2.0 (XSLT 2.0) use the lt, gt, le, ge and ne value comparison operators and don't use the general comparison operators for comparisons between two values.

Upvotes: 1

LarsH
LarsH

Reputation: 27994

@Kirill gave the main answer, but in XSLT 2.0 you can also use lt or le:

//ad[regyear lt 1999]

which may be more readable. In some cases, existential comparison operators like &lt; can have unexpected hairy implications, and lt avoids those.

Upvotes: 2

Kirill Polishchuk
Kirill Polishchuk

Reputation: 56182

Bigger or equals to 1999:

//ad[regyear &gt;= 1999]

Smaller or equals to 1998:

//ad[regyear &lt;= 1998]

Upvotes: 2

Related Questions