XPath 2.0 position() function and SaxonB 9.1.0.3

Having trouble installing Oxygen? Got a bug to report? Post it all here.
DAndres109
Posts: 4
Joined: Mon Dec 15, 2008 7:28 pm

XPath 2.0 position() function and SaxonB 9.1.0.3

Post by DAndres109 »

Hi,

I'm getting odd results when I use the position() function within an XSLT 2.0 stylesheet and the SaxonB 9.1.0.3 transformer.

Given a simple XML document such as the following

Code: Select all

<xml ...>
<table>
<table-row>
...
</table-row>
<table-row>
...
</table-row>
...
</table>
and an XSLT template:

Code: Select all

<xsl:template match="/table/table-row">
<xsl:value-of select="position()"/>
</xsl:template>
I expect to see an ordered list of numbers starting with 1. However, the transformation prints out the numbered sequence 2, 4, 6... (text nodes perhaps?) This does not occur with the SaxonSA transformer or with XPath 2.0 and XPath 2.0 SA searches.

I understand that this is most likely an issue with the transformer and not with Oxygen XML, but I thought I'd give this a try anyway.
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Re: XPath 2.0 position() function and SaxonB 9.1.0.3

Post by george »

Hi,

That is the correct behavior and I get the same also with Saxon SA. The cause is the built in template that matches on table and applies the templates on all child nodes of table. If you put a second template as below

Code: Select all


    <xsl:template match="/table/table-row">
<xsl:value-of select="position()"/>
</xsl:template>
<xsl:template match="/table/text()">
<xsl:text>[text </xsl:text>
<xsl:value-of select="position()"/>
<xsl:text>]</xsl:text>
</xsl:template>
you will see

[text 1]2[text 3]4[text 5]

as result.
If you want 1, 2, etc. for table rows then match on table and apply templates only on elements:

Code: Select all


    <xsl:template match="table">
<xsl:apply-templates select="*"/>
</xsl:template>
Best Regards,
George
George Cristian Bina
Post Reply