Re: [xsl] Initial whitespace in PI from XSLT, main body

Subject: Re: [xsl] Initial whitespace in PI from XSLT, main body
From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 7 May 2022 22:52:22 -0000
Syd, I see two ways (if you really need to) to maintain a PI whose string
value starts with a whitespace character:

  1. Enclose this value in some strippable non-whitespace characters (say
apostrophes or quotes), or,

  2. If the value is guaranteed not to end with a space character, just use
the reversed string value, and when you get that in your code, reverse it

Hope this helps,


On Sat, May 7, 2022 at 3:23 PM Bauman, Syd s.bauman@xxxxxxxxxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> MH> The relevant XSLT 3 spec section is
> and clearly says "6. In the case of xsl:processing-instruction
> any leading spaces in the resulting string are removed."
> DN>
> : " .  .  . 6. In the case of xsl:processing-instruction
> any leading spaces in the resulting string are removed."
> MK> Yes, Saxon strips any leading whitespace included in the content when
> you create a processing instruction using XSLT or XQuery.
> MK> XQuery 3.1 mandates this in B' XSLT 3.0 also does so, in
> MK> The problem is that there is no way of serializing a PI in such a way
> that leading whitespace in the content round-trips when the serialised
> output is re-parsed. But the serialization spec mandates that you should
> serialize the XML in such a way that round-tripping works.
> MK> It's unfortunate that the Data Model in B'6.5.1 doesn't state a
> constraint that the content of a PI must not contain leading whitespace.
> MK> XSLT 1.0 didn't say that xsl:processing-instruction should strip
> leading whitespace; and XSLT 2.0 didn't explicitly list this as an
> incompatible change. But then, in XSLT 1.0, there is no way of reading a
> processing instruction created by the transformation other than
> serialization followed by parsing, and this process loses any leading
> whitespace.
> Thank you, gentlemen!
> Seems to me, then, that Saxon is correct in stripping leading space on
> writing a PI; and that xsltproc (since it is only processing XSLT 1.0) is
> not *wrong* to include it, but will have a minor problem with this if and
> when it grows up to process XSLT 3.0.
> Thanks again, this has been yet another learning moment brought to you by
> the XSLT community. p
> XSL-List info and archive
> EasyUnsubscribe
> (by email)
> XSL-List info and archive <>
> EasyUnsubscribe <> (by
> email <>)

Dimitre Novatchev
Truly great madness cannot be achieved without significant intelligence.
To invent, you need a good imagination and a pile of junk
Never fight an inanimate object
To avoid situations in which you might make mistakes may be the
biggest mistake of all
Quality means doing it right when no one is looking.
You've achieved success in your field when you don't know whether what
you're doing is work or play
To achieve the impossible dream, try going to sleep.
Facts do not cease to exist because they are ignored.
Typing monkeys will write all Shakespeare's works in 200yrs.Will they write
all patents, too? :)
Sanity is madness put to good use.
I finally figured out the only reason to be alive is to enjoy it.

Current Thread