开发者

Position() and Issues with the value I am retrieving

<tableLayout>
        <tableColumn width="250"/>
        <tableDivider spaceAfter="0" spaceBefore="0"/>
        <tableColumn/>
        <tableDivider spaceAfter="0" spaceBefore="0"/>
        <tableColumn/>
    </tableLayout>

When selecting the width for the current "column" using the above data (not my decision to structure it like this) I am running into some issues.

   <xsl:attribute name="style">
                <xsl:text>width: </xsl:text>
                <xsl:value-of select="../../tableLayout/tableColumn[position()]/@width" />
                <xsl:text>px;</xsl:text>
            </xsl:attribute>

This is how I am accessing the "current width" for the columns I am constructing. Fairly straightforward in my opinion. If I put [1] instead of the call to position, it returns 250 for each column. If I put [2] or [3] it returns nothing. [4] causes an error as it should.

If I print position() I see 1, 2 and 3.

Bu开发者_开发知识库t when it's accessing the data through this method, I get 250 each time. Is this something wrong on what I'm doing or a issue with XSL?


The position() is relative to the wrong context (it is relative to the [] context, not your XSLT context node). Try this:

<xsl:variable name="position" select="position()" />
<xsl:value-of select="../../tableLayout/tableColumn[$position]/@width" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜