在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 < $rcount">
<xsl:element name="RowDefinition"/>
</xsl:if>
<xsl:if test="$r < $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 < $ccount">
<xsl:element name="ColumnDefinition"/>
</xsl:if>
<xsl:if test="$c < $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>
對我來說工作得很好,即使是20也是如此。使用MSXSL進行測試。 –
呃..很奇怪。那麼,我正在使用EditIx免費版。我會再試一次.. – MrSilverlight
我剛剛下載MSXML 4.0,並試圖在我的文件..他們的工作,就像你說的。正確的列數和行數。那麼爲什麼它不能和EditIX一起工作?......如果有人知道嗎? – MrSilverlight