我想从节点获取最大值
这是我的 XML:
<xml>
<NewDataSet>
<priorityResult>
<DXCount>32</DXCount>
<LHHight>12</LHHight>
<LHMedium>1</LHMedium>
<RiskPriority>6</RiskPriority>
</priorityResult>
</NewDataSet>
</xml>
我想使用此功能在 XSLT 页面中显示一个值:
var priority= parseInt(row["RiskPriority"]);
var newPriority= 0;
if ("DXCount" > 0 )
newPriority= 4;
else if ("LHHigh" > 0)
newPriority= 3;
else if ("LHMedium" > 0)
newPriority= 2;
return Math.max(priority, newPriority)
如何使用 xslt 获取此最大值?
我尝试这样做来显示节点值:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:output method="html" version="4.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="//priorityResult[SessionID != '']">
<p>
Priority :
<xsl:choose>
<xsl:when test="DXCount > 0">
4
</xsl:when>
<xsl:when test="LHHigh > 0">
3
</xsl:when>
<xsl:when test="LHMedium > 0">
2
</xsl:when>
<xsl:otherwise>
<xsl:value-of select ="RiskPriority"/>
</xsl:otherwise>
</xsl:choose>
</p>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
XSLT 1.0 没有max()
函数。如果我正确理解您的逻辑,您可以在 XSLT 1.0 中将其实现为:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="html"/>
<xsl:template match="/xml">
<xsl:for-each select="NewDataSet/priorityResult">
<xsl:variable name="newPriority">
<xsl:choose>
<xsl:when test="DXCount > 0">4</xsl:when>
<xsl:when test="LHHigh > 0">3</xsl:when>
<xsl:when test="LHMedium > 0">2</xsl:when>
</xsl:choose>
</xsl:variable>
<p>
<xsl:text>Priority :</xsl:text>
<xsl:choose>
<xsl:when test="RiskPriority > $newPriority">
<xsl:value-of select ="RiskPriority"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select ="$newPriority"/>
</xsl:otherwise>
</xsl:choose>
</p>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>