You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Anders Samuelson <an...@aspiro.com> on 2002/02/21 14:29:47 UTC
Different behaviour when using last()
Hi,
I have the following template snippet:
<xsl:template match="paragraph">
<xsl:apply-templates/>
<xsl:if test="child::node()[position()=last()]=text()">
<xsl:call-template name="br"/>
</xsl:if>
</xsl:template>
The purpose is that the 'br' template should only be called if the last child node of the paragraph element is a text node.
This wok fine with Microsoft XML Parser 3.0 but not with xalan 2.0.0 (or 2.3.0 fo that matter).
With xalan the test argument is always true (as far as i can tell from my tests).
Has anyone got a clue how I can get this to work?
Any help is greatly appriciated!
BR,
Anders Samuelson
Re: Different behaviour when using last()
Posted by Peter Davis <pd...@attbi.com>.
I haven't tested, but you might try:
child::node()[self::* or string-length(normalize-space(.)) > 0]
[position()=last()][self::text()]
I'm guessing that if you have an element at the end of your paragraph, you
probably have whitespace after that element. The child::node() axis would
also return the text node representing that space, and so the last node is
always a text node. So the first predicate makes it so that
[position()=last()] is only applied on elements or text nodes that have
non-whitespace.
If you've already accounted for all that, then, well, I'm at a loss for
ideas. :)
It's also probably better to use self::text() instead of "=text()", since the
'=' sign is used to compare *all* of the child nodes matching text(), instead
of just one; self::text() is probably more efficient.
On Thursday 21 February 2002 05:29, Anders Samuelson wrote:
> I have the following template snippet:
>
> <xsl:template match="paragraph">
> <xsl:apply-templates/>
> <xsl:if test="child::node()[position()=last()]=text()">
> <xsl:call-template name="br"/>
> </xsl:if>
> </xsl:template>
>
> The purpose is that the 'br' template should only be called if the last
> child node of the paragraph element is a text node. This wok fine with
> Microsoft XML Parser 3.0 but not with xalan 2.0.0 (or 2.3.0 fo that
> matter). With xalan the test argument is always true (as far as i can tell
> from my tests).
--
Peter Davis