Re: [xsl] invalid xpath?

Subject: Re: [xsl] invalid xpath?
From: Abel Braaksma <>
Date: Wed, 02 Jul 2008 14:53:42 +0200
Trevor Nicholls wrote:
Thank you Abel


   <xsl:when test="not(preceding-sibling::*)[starts-with($Arg,'&#x0a;')]">
    <xsl:call-template name="WS">


OK, the foregoing is invalid 1.0. So I tried modifying it to this:

 <xsl:when test="not(preceding-sibling::*) and starts-with($Arg,'&#x0a;')">
  <xsl:call-template name="WS">

Now there are no reported errors, but the test appears not to be working (at
least, there is an extra leading space in the output document wherever this
template has been called, compared with what Saxon was producing with the
original test).

In all honesty, I haven't delved into your stylesheet logic. What you are testing above is whether the current node has a preceding sibling element and whether $Arg starts with a newline character.

You don't show how the original template is called. You select the current node into $Arg (which could contain any number of children) and then you use string functions on that node, which essentially normalizes that node into a string, giving you no way whatsoever to extract any elements from it (they will all be stringized).

Is that what you want? Is that expected behavior?

If you want to remove the newlines you could make it easier on yourself by using:

translate($Arg, '&#xA;', '')

You also seem to have special cases. Why not use the template techniques for those cases? Let XSLT decide for you:

<xsl:template match="text()[following-sibling::nl]">

<xsl:template match="text()">

Then your KeepWS and WS named templates will become easier to program.

-- Abel --

Current Thread