我正在分析一个.xml文件,如下所示:
<xml>
<normalRange>100-200</normalRange>
<value>83</value>
</xml>
在.xls样式表中,我需要显示一个值,指示该值是在normalrange内、下方还是上方。
当显示来自ccr(healthcare hl7消息传递中的护理记录的连续性)xml文档的可读结果时,这是一个非常常见的问题。
最佳答案
<?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>
注意元素名“xml”是由XML 1.0 standard保留的,所以最好避免它。