2011-07-28 16 views
1

在XSLT:XSLT未向我的XML文件輸出正確數量的RowDefinition/ColumnDefinition元素。

一些奇怪的原因,當我指定的數值大於9 PARAM較大,只有2 RowDefinition/ColumnDefinition元件生成的XML文件中的輸出。 我對兩者都使用遞歸循環。

這是奇怪的,因爲它完全輸出9 < RowDefinition/> < ColumnDefinition/>元素時我給9作爲在拉伸網格的呼叫模板RCOUNT/ccount PARAM值。如果我給出10作爲參數,那麼突然我在我的生成的XML文件中只獲得2個元素RowDefinition/> < ColumnDefinition/>元素。

這是怎麼發生的?我需要28行和6個COLS ..

見代碼:與MSXSL獲得

<xsl:output method="xml" indent="yes"/> 

<xsl:template match="/"> 
    <xsl:call-template name="draw-grid"> 
     <!--outputs only 2 RowDefinition elements..--> 
     <xsl:with-param name="rcount">10</xsl:with-param> 
     <!--works perfectly: I get 9 ColumnDefinition elements--> 
     <xsl:with-param name="ccount">9</xsl:with-param>    
     <xsl:with-param name="r">0</xsl:with-param> 
     <xsl:with-param name="c">0</xsl:with-param> 
    </xsl:call-template> 
</xsl:template> 

<xsl:template name="draw-grid"> 
    <xsl:param name="rcount"/> 
    <xsl:param name="ccount"/> 
    <xsl:param name="r"/> 
    <xsl:param name="c"/> 

    <xsl:element name="Grid"> 

     <xsl:element name="Grid.RowDefinitions"> 
      <xsl:call-template name="draw-rows"> 
       <xsl:with-param name="rcount"> 
        <xsl:value-of select="$rcount"/> 
       </xsl:with-param> 
       <xsl:with-param name="r"> 
        <xsl:value-of select="$r"/> 
       </xsl:with-param> 
      </xsl:call-template> 
     </xsl:element> 

     <xsl:element name="Grid.ColumnDefinitions"> 
      <xsl:call-template name="draw-cols"> 
       <xsl:with-param name="ccount"> 
        <xsl:value-of select="$ccount"/> 
       </xsl:with-param> 
       <xsl:with-param name="c"> 
        <xsl:value-of select="$c"/> 
       </xsl:with-param> 
      </xsl:call-template> 
     </xsl:element> 

    </xsl:element> 
</xsl:template> 

<xsl:template name="draw-rows"> 
    <xsl:param name="rcount"/> 
    <xsl:param name="r"/> 

    <xsl:if test="$r &lt; $rcount"> 
     <xsl:element name="RowDefinition"/> 
    </xsl:if> 

    <xsl:if test="$r &lt; $rcount"> 
     <xsl:call-template name="draw-rows"> 
      <xsl:with-param name="r"> 
       <xsl:value-of select="$r + 1"/> 
      </xsl:with-param> 
      <xsl:with-param name="rcount"> 
       <xsl:value-of select="$rcount"/> 
      </xsl:with-param> 
     </xsl:call-template> 
    </xsl:if> 
</xsl:template> 

<xsl:template name="draw-cols"> 
    <xsl:param name="ccount"/> 
    <xsl:param name="c"/> 

    <xsl:if test="$c &lt; $ccount"> 
     <xsl:element name="ColumnDefinition"/> 
    </xsl:if> 

    <xsl:if test="$c &lt; $ccount"> 
     <xsl:call-template name="draw-cols"> 
      <xsl:with-param name="c"> 
       <xsl:value-of select="$c + 1"/> 
      </xsl:with-param> 
      <xsl:with-param name="ccount"> 
       <xsl:value-of select="$ccount"/> 
      </xsl:with-param> 
     </xsl:call-template> 
    </xsl:if> 
</xsl:template> 

+0

對我來說工作得很好,即使是20也是如此。使用MSXSL進行測試。 –

+0

呃..很奇怪。那麼,我正在使用EditIx免費版。我會再試一次.. – MrSilverlight

+0

我剛剛下載MSXML 4.0,並試圖在我的文件..他們的工作,就像你說的。正確的列數和行數。那麼爲什麼它不能和EditIX一起工作?......如果有人知道嗎? – MrSilverlight

回答

1

結果(26,8):

<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition /> 
     <RowDefinition /> 
     <RowDefinition /> 
     <RowDefinition /> 
     <RowDefinition /> 
     <RowDefinition /> 
     <RowDefinition /> 
     <RowDefinition /> 
     <RowDefinition /> 
     <RowDefinition /> 
     <RowDefinition /> 
     <RowDefinition /> 
     <RowDefinition /> 
     <RowDefinition /> 
     <RowDefinition /> 
     <RowDefinition /> 
     <RowDefinition /> 
     <RowDefinition /> 
     <RowDefinition /> 
     <RowDefinition /> 
     <RowDefinition /> 
     <RowDefinition /> 
     <RowDefinition /> 
     <RowDefinition /> 
     <RowDefinition /> 
     <RowDefinition /> 
     <RowDefinition /> 
     <RowDefinition /> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition /> 
     <ColumnDefinition /> 
     <ColumnDefinition /> 
     <ColumnDefinition /> 
     <ColumnDefinition /> 
     <ColumnDefinition /> 
    </Grid.ColumnDefinitions> 
</Grid> 
+0

是的,但是我想知道的是爲什麼它在EditIx中不起作用。我需要它在EditIx中工作。 – MrSilverlight

+0

Buggy應用程序?您是否將其測試爲XSLT 1.0或2.0? –

+0

我在XSLT 2.0中測試它。 – MrSilverlight

0

這似乎是EditIx的一個問題。

如果您的文件是XSLT版本1.0(請參閱文件頂部的'版本'屬性),此代碼在EditIx中正常工作。 如果使用命令行工具MSXML(當前版本:4.0),此代碼也可以正常工作。 EditIx Free Version中的XSLT 2.0似乎存在一些問題,並帶有這段代碼。