2011-04-19 69 views
2

當我用我的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> 
+1

問題出在您未向我們展示的代碼中。 – 2011-04-19 13:02:04

回答

2

$freq真的多少?

使用[@frequency > number($freq)]強制澆鑄參數

+0

好的,謝謝你,這個伎倆。奇怪的是,其他時候我不需要強制鑄造。 – Jeroen 2011-04-19 09:37:16

+0

很高興知道它的作品。是的,取決於數據如何「存儲」以及如何將它傳遞給填表模板 – jujule 2011-04-19 09:51:50

+1

'>'操作員執行隱式轉換,從http://www.w3.org/TR/xpath/#booleans:_ 「通過將兩個對象轉換爲數字並根據IEEE 754」比較數字來比較對象。這不是問題。 – 2011-04-19 13:05:49