當我用我的XPath表達式用硬編碼的變量,它給了我正確的結果:XPath表達式中使用XSLT PARAM
<xsl:value-of select="count(//n-gram[@frequency > 50])"/>
但是,當我用我的模板的一個參數,它給了我一個完成不同的結果:
<xsl:value-of select="count(//n-gram[@frequency > $freq])"/>
有人能告訴我我做錯了什麼嗎?
完整代碼作爲參考(我生成一個XAML文件與XSL):
XML文件:
<n-grams>
<n-gram frequency="3">r n u</n-gram>
<n-gram frequency="1">o H e</n-gram>
<n-gram frequency="2">r n t</n-gram>
<n-gram frequency="2">N i c</n-gram>
<n-gram frequency="2">a u l</n-gram> ...
XSL模板:
<xsl:template name="fill-table">
<xsl:param name="freq"/>
<xsl:param name="startRow"/>
<xsl:param name="startCol"/>
<xsl:call-template name="get-textblock">
<xsl:with-param name="row">
<xsl:value-of select="$startRow "/>
</xsl:with-param>
<xsl:with-param name="column">
<xsl:value-of select="$startCol + 1"/>
</xsl:with-param>
<xsl:with-param name="text">
<xsl:value-of select="count(//n-gram[@frequency > $freq])"/>
</xsl:with-param>
<xsl:with-param name="type">
<xsl:value-of select="'ValueText'"/>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="get-textblock">
<xsl:param name="row"/>
<xsl:param name="column"/>
<xsl:param name="text"/>
<xsl:param name="type"/>
<xsl:param name="colspan" select="1"/>
<xsl:element name="TextBlock">
<xsl:attribute name="Grid.Column">
<xsl:value-of select="$column"/>
</xsl:attribute>
<xsl:attribute name="Grid.Row">
<xsl:value-of select="$row"/>
</xsl:attribute>
<xsl:attribute name="Style">
<xsl:value-of select="concat('{StaticResource ',$type,'}')"/>
</xsl:attribute>
<xsl:attribute name="Grid.ColumnSpan">
<xsl:value-of select="$colspan"/>
</xsl:attribute>
<xsl:value-of select="$text"/>
</xsl:element>
</xsl:template>
問題出在您未向我們展示的代碼中。 – 2011-04-19 13:02:04