xsl-list
[Top] [All Lists]

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

2022-05-07 17:52:33
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
back.

Hope this helps,

Dimitre

On Sat, May 7, 2022 at 3:23 PM Bauman, Syd 
s(_dot_)bauman(_at_)northeastern(_dot_)edu <
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

MH> The relevant XSLT 3 spec section is
https://www.w3.org/TR/xslt-30/#constructing-simple-content
<https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.w3.org%2FTR%2Fxslt-30%2F%23constructing-simple-content&data=05%7C01%7Cs.bauman%40northeastern.edu%7Cf7d75cb09c2b4004a57f08da3072f8d5%7Ca8eec281aaa34daeac9b9a398b9215e7%7C0%7C0%7C637875568061834037%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=IvUUGrl1Pg7%2Bms%2FUToogBhl8idaun40GEvxAf%2Bn5aCk%3D&reserved=0>
and clearly says "6. In the case of xsl:processing-instruction
<https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.w3.org%2FTR%2Fxslt-30%2F%23element-processing-instruction&data=05%7C01%7Cs.bauman%40northeastern.edu%7Cf7d75cb09c2b4004a57f08da3072f8d5%7Ca8eec281aaa34daeac9b9a398b9215e7%7C0%7C0%7C637875568061990277%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=IcC2BVnqQQf0D5o4zlusIcLtGpzwNvU%2BtA%2Foxtuc9Xk%3D&reserved=0>,
any leading spaces in the resulting string are removed."

DN> https://www.w3.org/TR/xslt-30/#constructing-simple-content
<https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.w3.org%2FTR%2Fxslt-30%2F%23constructing-simple-content&data=05%7C01%7Cs.bauman%40northeastern.edu%7C9db73cd3a721407df65b08da3073d667%7Ca8eec281aaa34daeac9b9a398b9215e7%7C0%7C0%7C637875571320678621%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=skqprH7CYK0yWW4psy8dTVb70sX9dXmWCVrgC4OyIKY%3D&reserved=0>
: " .  .  . 6. In the case of xsl:processing-instruction
<https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.w3.org%2FTR%2Fxslt-30%2F%23element-processing-instruction&data=05%7C01%7Cs.bauman%40northeastern.edu%7C9db73cd3a721407df65b08da3073d667%7Ca8eec281aaa34daeac9b9a398b9215e7%7C0%7C0%7C637875571320678621%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=qYVrPuaEXCFFSZ79WMJaPNnD8IJqt0ev1KDhpBVpffw%3D&reserved=0>,
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 §3.9.3.5. XSLT 3.0 also does so, in §5.7.2.
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 §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. 🙂

XSL-List info and archive
<https://nam12.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.mulberrytech.com%2Fxsl%2Fxsl-list&data=05%7C01%7Cs.bauman%40northeastern.edu%7C601616d493e64c00492d08da30761864%7Ca8eec281aaa34daeac9b9a398b9215e7%7C0%7C0%7C637875581017378461%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=o%2FLF7jAteBqm6gssBF3t3KEdJVSqUNV4XdKeb%2FQxuXY%3D&reserved=0>
EasyUnsubscribe
<https://nam12.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists.mulberrytech.com%2Funsub%2Fxsl-list%2F649132&data=05%7C01%7Cs.bauman%40northeastern.edu%7C601616d493e64c00492d08da30761864%7Ca8eec281aaa34daeac9b9a398b9215e7%7C0%7C0%7C637875581017378461%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=4%2ByPRY41HK9Qsm5E0wPbU82HWokYmN9T1M9PBk%2B8VRQ%3D&reserved=0>
(by email)
XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/782854> (by
email <>)



-- 
Cheers,
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.
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>