xsl-list
[Top] [All Lists]

Determine the position of an element relative to its sibling

2005-03-01 13:38:21
I want to use the position of an element ralative to its siblings to
construct an xpath to another element.

For example,

Input:
<TABLE>
        <THEAD>
                <TR>
                        <TD>Header Col 1<A class="sort">Sort</A></TD>
                        <TD>Header Col 2<A class="sort">Sort</A></TD>
                </TR>
        </THEAD>
        <TBODY>
                <TR>
                        <TD id="column1">Col 1 Prototype</TD>
                        <TD id="column2">Col 2 Prototype</TD>
                </TR>
        </TBODY>
</TABLE>

Template:
<xsl:template match="A[(_at_)class='sort']">
        <A>
                <xsl:attribute name="url">
                        base?field=<xsl:value-of
select="ancestor::TABLE/TBODY/TR/TD[<what goes here?>]/@id"/>
                </xsl:attribute>
        </A>
</xsl:template>

Output:
<TABLE>
        <THEAD>
                <TR>
                        <TD>Header 1<A url="base?field=column1"
class="sort">Sort</A></TD>
                        <TD>Header 2<A url="base?field=column2"
class="sort">Sort</A></TD>
                </TR>
        </THEAD>
        <TBODY>
                <TR>
                        <TD id="column1">Col 1 Prototype</TD>
                        <TD id="column2">Col 2 Prototype</TD>
                </TR>
        </TBODY>
</TABLE>

Things I have tried in <what goes here?>:

position()

for $i in ../TD return if (generate-id(../TD[$i]) = generate-id(..))
then $i else 0

And various other things to no avail. I'm sure there is an easy way to
do this but searching for position and element adnosium finds thousands
of hits. My eyeballs are crosseyed from reading so many wonderful list
entries about stuff that I'm sure will help me in the long run but are
not solving my immediate problem. 

Thanks for any advice, hints, etc.

Douglas Ross 
Developer, HTML UI Framework 
Kronos 
E-mail: dross(_at_)kronos(_dot_)com 
www.kronos.com 


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>