[xsl] Calling position() on a parent element

Subject: [xsl] Calling position() on a parent element
From: Graham Ashton <gashton@xxxxxxxxxxx>
Date: 08 May 2002 15:33:16 +0100
Hi.

I'm trying to convert this simple markup (which looks like HTML, but
isn't):

  <tr>
    <td>
      <label>Hello World!</label>
    </td>
    <td>
      <label>Foo</label>
    </td>
  </tr>

into something akin to this:

  <label>
    <text>Hello World!</text>
    <left_attach>0</left_attach>
  </label>
  <label>
    <text>Foo</text>
    <left_attach>1</left_attach>
  </label>

The <left_attach> elements in the output tell the label or the button
which table cell they should appear in. I'm having real trouble getting
hold of the values for <left_attach> from my source input, as I can't
determine the position of the <td> element that a <label> belongs to,
from the context of a <label>'s template.

This is close to what I'd like to be able to do:

<xsl:template match="td/label">
  <label>
    <text><xsl:value-of select="."/></text>
    <left_attach><xsl:value-of select="position(parent)"/></left_attach>
  </label>
</xsl:template>

Obviously, the "position(parent)" part is wrong (it just illustrates
what I'd like to do).

Is there a way for the template that handles <label> elements to
determine the position of <td> elements, within the <tr>?

I'm using the latest libxslt. Thanks.

-- 
Graham Ashton


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread