I'm parsing an .xml file like:
<xml>
<normalRange>100-200</normalRange>
<value>83</value>
</xml>
In an .xls stylesheet I need to display a value indicating whether the value is within the normalRange, below it, or above it.
This is a very common problem when displaying Human Readable results from the CCR (Continuity of Care Record in Healthcare HL7 messaging) xml document.
<?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 < $low">
<output>below</output>
</xsl:when>
<xsl:when test="$value > $high">
<output>above</output>
</xsl:when>
<xsl:otherwise>
<output>within</output>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Note that element name "xml" is reserved by XML 1.0 standard, so it's probably good idea to avoid it.
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