![]() |
1
10
我们不会“保存xsl:for-each中发生的迭代”,因为 XSLT is a functional language 变量是不可变的。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:call-template name="maximum"> <xsl:with-param name="pNodes" select="*/Question"/> </xsl:call-template> </xsl:template> <xsl:template name="maximum"> <xsl:param name="pNodes"/> <xsl:variable name="vNumNodes" select="count($pNodes)"/> <xsl:choose> <xsl:when test="$vNumNodes = 1"> <xsl:value-of select="count($pNodes[1]/Response)"/> </xsl:when> <xsl:otherwise> <xsl:variable name="vHalf" select="floor($vNumNodes div 2)"/> <xsl:variable name="vMax1"> <xsl:call-template name="maximum"> <xsl:with-param name="pNodes" select="$pNodes[not(position() > $vHalf)]"/> </xsl:call-template> </xsl:variable> <xsl:variable name="vMax2"> <xsl:call-template name="maximum"> <xsl:with-param name="pNodes" select="$pNodes[position() > $vHalf]"/> </xsl:call-template> </xsl:variable> <xsl:value-of select= "$vMax1*($vMax1 >= $vMax2) + $vMax2*($vMax2 > $vMax1)"/> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> 应用于提供的XML文档时: <Survey> <Question> <Response text="Website" /> <Response text="Print Ad" /> </Question> <Question> <Response text="Yes" /> </Question> </Survey> 产生了想要的结果: 2.
名为
|
![]() |
JobProcessTask · 如何读取此xpath表达式? 2 年前 |
![]() |
MBF · PHP导入/解析XML文件内容保存到数据库 3 年前 |
![]() |
TenkMan · SQL Server XML嵌套值查询表单990 3 年前 |
![]() |
Mohan.Murali.Peddini · XSLT模板循环记录 3 年前 |