XSLT没有向我的XML文件输出正确数量的RowDefinition / ColumnDefinition元素。

时间:2011-07-28 15:00:45

标签: xml xaml xslt

在XSLT中:

由于某些奇怪的原因,当我指定一个大于9的数字作为参数时,在生成的XML文件中只输出2个RowDefinition / ColumnDefinition元素。 我对两者使用递归循环。

这很奇怪,因为它完美输出9< RowDefinition /> < ColumnDefinition />当我在绘图网格的调用模板中给出9作为rcount / ccount的参数值时的元素。如果我给10作为参数,那么突然我只得到2< RowDefinition /> < ColumnDefinition />我生成的XML文件中的元素。

为什么会这样?我需要28行和6列..

参见代码:

<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>

2 个答案:

答案 0 :(得分:1)

使用MSXSL(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>

答案 1 :(得分:0)

这似乎是EditIx的一个问题。

如果您的文件是XSLT版本1.0(请参阅文件顶部的“版本”属性),此代码在EditIx中可以正常工作。 如果使用命令行工具MSXML(当前版本:4.0),此代码也可以正常工作。 在EditIx免费版中,XSLT 2.0似乎存在问题,并带有这段特殊的代码。