You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Kurt Heston <ku...@yahoo.com> on 2001/04/19 20:28:50 UTC

problem with preceding-sibling and following-sibling

I'm trying to produce an HTML table and am running into some difficulty.  My
XML document has nodes with a "row" attribute.  When the number of the row
attribute changes, I need to start a new row.  My code looks something like:

<xsl:if test="preceding-sibling::fld/@row &lt @row">
	<!-- new row -->
</xsl:if>

The problem is that preceding-sibling seems to always want to return the
sibling that is first in the tree level, not the one that directly precedes
the current node on the same level, no matter if there are 2 nodes or 400.
The behavior of following-sibling is similar, returning only the last node
in the level.

Is this a bug?  I'm currently using Xalan-1.2.2, if I upgraded to Xalan-2
would this problem be fixed?


Re: problem with preceding-sibling and following-sibling

Posted by James Melton <ja...@cylogix.com>.
James Melton wrote:
> 
> 1. "preceding-sibling::fld/@row" will return a node-set of "row"
> attributes.

As I think about this statement it seems nonsensical. An attribute is
not a node so you cannot have a node-set of attributes. 

Try: "preceding-sibling::fld[1]/@row" (again untested) to see if that is
what you want.

Sorry for the messy first explanation.

Jim

____________________________________________________________
James Melton                 CyLogix
609.750.5190                 609.750.5100
james.melton@cylogix.com     www.cylogix.com

RE: problem with preceding-sibling and following-sibling

Posted by Kurt Heston <ku...@yahoo.com>.
Essentially what I'm trying to do is make decisions about how to process the
current node in a for-each loop based on values that both the node that was
just processed and the node that will be processed next have.  Since I can't
update a variable with the values I need to check, I'd like to be able to
determine things based on a node's position in the tree.  This is how I got
into the whole preceding/following-sibling mess.  Would the "position"
function get me where I want to go?  Since the preceding-sibling code has
not been tested, how do I get where I need to go?

-----Original Message-----
From: Kurt Heston [mailto:kurtheston@yahoo.com]
Sent: Thursday, April 19, 2001 12:47 PM
To: xalan-dev@xml.apache.org
Subject: RE: problem with preceding-sibling and following-sibling


This "preceding-sibling::fld/@row" and "preceding-sibling::fld/@row[1]"
return the same thing.  It looks like the "reverse document order" part may
not be working.  Is there a work around?



-----Original Message-----
From: James Melton [mailto:james.melton@cylogix.com]
Sent: Thursday, April 19, 2001 12:15 PM
To: xalan-dev@xml.apache.org
Subject: Re: problem with preceding-sibling and following-sibling


I do not think you are seeing a bug.

I think what will happen with this code is:
1. "preceding-sibling::fld/@row" will return a node-set of "row"
attributes.
2. This nodeset will be compared to the string resulting from the
current node's "row" attribute. That comparison using "&lt" compares
each node of the node-set with the string.
3. The first (in document order) "row" attribute apparently is included
in this node-set, so it will be compared to the string from the current
"row" attribute (ignoring any short-circuit optimization that may be
done).

I think you want to look only at the immediately preceding sibling.
Perhaps something like: "preceding-sibling::fld/@row[1]" (note that this
is untested code). Of course following-sibling works similarly.

Jim.


Kurt Heston wrote:
>
> When the number of the row
> attribute changes, I need to start a new row.  My code looks something
like:
>
> <xsl:if test="preceding-sibling::fld/@row &lt @row">
>         <!-- new row -->
> </xsl:if>
>

____________________________________________________________
James Melton                 CyLogix
609.750.5190                 609.750.5100
james.melton@cylogix.com     www.cylogix.com


RE: problem with preceding-sibling and following-sibling

Posted by Kurt Heston <ku...@yahoo.com>.
This "preceding-sibling::fld/@row" and "preceding-sibling::fld/@row[1]"
return the same thing.  It looks like the "reverse document order" part may
not be working.  Is there a work around?



-----Original Message-----
From: James Melton [mailto:james.melton@cylogix.com]
Sent: Thursday, April 19, 2001 12:15 PM
To: xalan-dev@xml.apache.org
Subject: Re: problem with preceding-sibling and following-sibling


I do not think you are seeing a bug.

I think what will happen with this code is:
1. "preceding-sibling::fld/@row" will return a node-set of "row"
attributes.
2. This nodeset will be compared to the string resulting from the
current node's "row" attribute. That comparison using "&lt" compares
each node of the node-set with the string.
3. The first (in document order) "row" attribute apparently is included
in this node-set, so it will be compared to the string from the current
"row" attribute (ignoring any short-circuit optimization that may be
done).

I think you want to look only at the immediately preceding sibling.
Perhaps something like: "preceding-sibling::fld/@row[1]" (note that this
is untested code). Of course following-sibling works similarly.

Jim.


Kurt Heston wrote:
>
> When the number of the row
> attribute changes, I need to start a new row.  My code looks something
like:
>
> <xsl:if test="preceding-sibling::fld/@row &lt @row">
>         <!-- new row -->
> </xsl:if>
>

____________________________________________________________
James Melton                 CyLogix
609.750.5190                 609.750.5100
james.melton@cylogix.com     www.cylogix.com


Re: problem with preceding-sibling and following-sibling

Posted by James Melton <ja...@cylogix.com>.
I do not think you are seeing a bug. 

I think what will happen with this code is: 
1. "preceding-sibling::fld/@row" will return a node-set of "row"
attributes. 
2. This nodeset will be compared to the string resulting from the
current node's "row" attribute. That comparison using "&lt" compares
each node of the node-set with the string. 
3. The first (in document order) "row" attribute apparently is included
in this node-set, so it will be compared to the string from the current
"row" attribute (ignoring any short-circuit optimization that may be
done). 

I think you want to look only at the immediately preceding sibling.
Perhaps something like: "preceding-sibling::fld/@row[1]" (note that this
is untested code). Of course following-sibling works similarly.

Jim.


Kurt Heston wrote:
> 
> When the number of the row
> attribute changes, I need to start a new row.  My code looks something like:
> 
> <xsl:if test="preceding-sibling::fld/@row &lt @row">
>         <!-- new row -->
> </xsl:if>
> 

____________________________________________________________
James Melton                 CyLogix
609.750.5190                 609.750.5100
james.melton@cylogix.com     www.cylogix.com