Is it possible to select only those values that lay between 2 given values using xslt?
i.e.
<value>1</value>
<value>1.2</value>
<value>1.3</value>
<value>1.4</value>
<value>1.5</value>
<value>2</value>
<value>2.1</value>
<value>2.3</value>
<value>2.4</value>
<value>2.5</value>
I only want to display values between 1 and 2.
Unlike the other answer I prefer to go with Identity Override
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="value[. < 1 or . > 2]"/>
</xsl:stylesheet>
outputs:
<root>
<value>1</value>
<value>1.2</value>
<value>1.3</value>
<value>1.4</value>
<value>1.5</value>
<value>2</value>
</root>
Certainly:
select="value[. > 1 and . < 2]"
if you want to include 1 and 2:
select="value[. >= 1 and . <= 2]"
if the top and bottom limits are in variables (using $min and $max as examples here):
select="value[. > $min and . < $max]"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With