In .xsl, take a range value, such as โ€œ130-210,โ€ and determine if โ€œ86โ€ or โ€œ458โ€ is in that number range

I am parsing an XML file, for example:

<xml>
  <normalRange>100-200</normalRange>
  <value>83</value>
</xml>

In the .xls stylesheet, I need to display a value indicating whether the value is within the normal range, below or above it.

This is a very common problem when displaying Human Readable results from the CCR (Continuity of Care Record XML document in Healthcare HL7 messaging) XML document.

+5
source share
1 answer
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
    <xsl:variable name="value" select="/xml/value"/>
    <xsl:variable name="low" select="substring-before(/xml/normalRange, '-')"/>
    <xsl:variable name="high" select="substring-after(/xml/normalRange, '-')"/>

    <xsl:choose>
        <xsl:when test="$value &lt; $low">
            <output>below</output>
        </xsl:when>
        <xsl:when test="$value &gt; $high">
            <output>above</output>
        </xsl:when>
        <xsl:otherwise>
            <output>within</output>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

</xsl:stylesheet>

Note that the xml element name is reserved by the XML 1.0 standard , so it is probably a good idea to avoid it.

+7

All Articles