Re: AW: document() and position()

Subject: Re: AW: document() and position()
From: Gary L Peskin <garyp@xxxxxxxxxxxx>
Date: Tue, 25 Jul 2000 12:31:13 -0700
I have found the source of this problem.  It lies in the
DTMProxy.equals() method.  The current implementation only checks to see
if the node numbers are equal, assuming the two underlying DTM trees are
the same.  This simple fix corrects that problem.

Scott, should I show the fix for 2.0 as well or will you make sure that
this change is reflected there as well?

cvs diff DTMProxy.java (in directory
D:\Xalan-dev\xml-xalan\src\org\apache\xalan\xpath\dtm)
Index: DTMProxy.java
===================================================================
RCS file:
/home/cvspublic/xml-xalan/src/org/apache/xalan/xpath/dtm/DTMProxy.java,v
retrieving revision 1.11
diff -r1.11 DTMProxy.java
120c120
<       return (dtmp.node == this.node);
---
>       return (dtmp.node == this.node) && (dtmp.dtm == this.dtm);

HTH,
Gary

Jeni Tennison wrote:
> 
> Dirk,
> 
> >If I do anything like this:
> >
> ><xsl:template match="/">
> >   <xsl:apply-templates select="document(/page/folder)/news[@show = 'true']"
> >/>
> ></xsl:template>
> >
> ><xsl:template match="news">
> >   <xsl:variable name="index" select="position()" />
> >   News item <xsl:value-of select="$index" />
> >   ...
> ></xsl:template>
> >
> >I will allways get '1'. Because the 'news' tag is allways the number one
> >position in the current xml file.
> 
> I'm very surprised that this is always generating '1'.  What XSLT processor
> are you using?  When you use the position() function, it should look at the
> position of the current node in the *current node list*, not in the
> 'current XML file'.
> 
> Within the template, the current node is the node that's been matched - in
> this case the 'news' element.  The current node list is set by the
> xsl:apply-templates that was used to apply the template.  In this case, the
> current node list consists of the nodes specified by the XPath:
> 
>   document(/page/folder)/news[@show = 'true']
> 
> In your example, this list has two nodes in it: the 'news' element from
> 2.xml and the 'news' element from 4.xml.  So the position() of the first
> should be 1 and the position() of the second should be 2.
> 
> I have tested the following files in SAXON and it gives the result that I
> think you are after.  Please let me know what the resulting output should
> look like if I've misinterpreted you.
> 
> ---- test.xml ----
> <?xml version="1.0"?>
> <?xml-stylesheet type="text/xsl" href="test.xsl" ?>
> <page>
>   <folder>1.xml</folder>
>   <folder>2.xml</folder>
>   <folder>3.xml</folder>
>   <folder>4.xml</folder>
> </page>
> ----
> ---- 1.xml ----
> <news show="false">
>   1.xml
> </news>
> ----
> ---- 2.xml ----
> <news show="true">
>   2.xml
> </news>
> ----
> ---- 3.xml ----
> <news show="false">
>   3.xml
> </news>
> ----
> ---- 4.xml ----
> <news show="true">
>   4.xml
> </news>
> ----
> ---- test.xsl ----
> <?xml version="1.0"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>                 version="1.0">
> 
> <xsl:template match="/">
>    <xsl:apply-templates select="document(/page/folder)/news[@show='true']" />
> </xsl:template>
> 
> <xsl:template match="news">
>   News item <xsl:value-of select="position()" />[<xsl:value-of
>   select="normalize-space(.)" />]
> </xsl:template>
> 
> </xsl:stylesheet>
> ----
> 
> Command line:  saxon -a -t -o out.xml test.xml
> 
> ---- out.xml ----
> <?xml version="1.0" encoding="utf-8" ?>
>   News item 1 [2.xml]
> 
>   News item 2 [4.xml]
> ----
> 
> I hope this helps,
> 
> Jeni
> 
> Dr Jeni Tennison
> Epistemics Ltd * Strelley Hall * Nottingham * NG8 6PE
> tel: 0115 906 1301 * fax: 0115 906 1304 * email: jeni.tennison@xxxxxxxxxxxxxxxx


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


Current Thread