xsl-list
[Top] [All Lists]

RE: Comparing nodes in axis

2004-12-17 10:20:22

Is it correct to use expressions like these ones:

                        <xsl:if test="parent::menu=(//menu)[$pos]">
                            <xsl:text>1</xsl:text>
                        </xsl:if>

                       <xsl:if test="ancestor::menu=(//menu)[$pos]">
                            <xsl:text>0</xsl:text>
                        </xsl:if>

to compare the context node with another known node?

You are comparing the nodes for equality, whereas your description suggests
you want to compare them for identity. To compare whether $A and $B are the
same node, use ($A is $B) in XPath 2.0, or (count($A|$B)=1) in XPath 1.0.

Michael Kay
http://www.saxonica.com/


In the first example i'm saying

"If the context node, the one now being processed, is the 
parent of the 
menu node at absolute position $pos"

and

"If the the menu node at absolute position $pos is one of the 
ancestors 
of the context node"?

It is apparently working OK, but i never saw such comparisons 
being made...


As a side question, i tend to make things like

                        <xsl:if test="parent::menu=(//menu)[$pos]">
                            <xsl:text>1</xsl:text>
                        </xsl:if>
                        <xsl:if 
test="not(parent::menu=(//menu)[$pos])">
                            <xsl:text>0</xsl:text>
                        </xsl:if>

Is there any drawback in doing this insted of choose/when/otherwise?

Thanks.


--~------------------------------------------------------------------
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>
--~--




--~------------------------------------------------------------------
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>
--~--