p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

xslt thread: comparing current attr with preceding attr


Message #1 by "kevin ritter" <kevin.ritter@j...> on Fri, 27 Jul 2001 16:47:31 -0500
xsl:if test="@id=preceding-sibling::answer/@id[1]"

Note:

preceding-sibling rather than preceding, because you're only interested in
elements that are children of the same <answers> element (I assume)

[1] because you're only interested in the immediately preceding one (I
assume).

I'm not sure what you mean by "I don't get a return on $idchecker". In each
case it will be a result tree fragment, but its content will be different in
each case. I'm not sure why you're putting the result into a result tree
fragment, because you haven't shown us the context.

>
> When I try to use the following expression, I don't get a return on
> $idchecker.
>            <xsl:variable name="idchecker">
>              <xsl:for-each select="answer[not(@id 
> preceding::answer/@id)]">
>                <xsl:value-of select="@id"/>
>              </xsl:for-each>
>            </xsl:variable>

I would expect this to put something in idchecker, provided the context
element is the <answers> element.
>
> When I try to use the following expression, I get "unexpected token"
>
>            <xsl:variable name="idchecker">
>              <xsl:for-each select="/[not(@id = preceding::/@id)]">
>                <xsl:value-of select="@id"/>
>              </xsl:for-each>
>            </xsl:variable>

You can't apply a predicate to the root node.
>
> When I try to use the following expression, I don't get a return on
> $idchecker
>
>            <xsl:variable name="idchecker">
>              <xsl:for-each select="/*[not(@id = preceding::*/@id)]">
>                <xsl:value-of select="@id"/>
>              </xsl:for-each>
>            </xsl:variable>
>
> When I try to use the following expression, I don't get a return on
> $idchecker
>
>            <xsl:variable name="idchecker">
>              <xsl:for-each select="/[not(@id = preceding::*/@id)]">
>                <xsl:value-of select="@id"/>
>              </xsl:for-each>
>            </xsl:variable>
>
> How do I get this to work..
>
I suspect most of your problems are to do with getting the context node
wrong. Can't tell, because you haven't shown enough context!

Mike Kay
Software AG


  Return to Index