views:

25

answers:

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

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

+1  A: 

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" />
Lucero
Literally seconds before loading up this page, likely as you were writing this post, I thought of the same thing. Great minds and everything! ;)
bobber205