5

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.

skaffman
  • 398,947
  • 96
  • 818
  • 769
MikeN
  • 45,039
  • 49
  • 151
  • 227

1 Answers1

7
<?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 element name "xml" is reserved by XML 1.0 standard, so it's probably good idea to avoid it.

Grzegorz Szpetkowski
  • 36,988
  • 6
  • 90
  • 137
  • 1
    Thanks for the help! I owe you $5 American. Let me know if you are looking for a job. – MikeN May 31 '11 at 03:40