In .xsl, take a range value like "130-210", and determine if "86" or "458" is within that numeric range
Asked Answered
M

1

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.

Misdate answered 31/5, 2011 at 3:4 Comment(2)
Are you doing this within spreadsheet cells or within VBA? In either case, just check if Value < MinValue or Value > MaxValue.Prosper
No, this is in raw .xml and .xls files. (No spreadsheet or VBA.)Misdate
O
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.

Overbuild answered 31/5, 2011 at 3:23 Comment(1)
Thanks for the help! I owe you $5 American. Let me know if you are looking for a job.Misdate

© 2022 - 2024 — McMap. All rights reserved.