Re: [xsl] Source code formatting
2020-07-28 16:37:39
I recently thought about this when I wondered how we can preserve
whitespace in attributes when migrating XProc 1.0 documents (that often
include inline XSLT with multi-line attributes, in addition to their own
multiline attributes) to XProc 3.0.
At first I thought that the easiest solution would be to patch xerces so
that it optionally doesn’t perform whitespace normalization in
attributes any more.
But for migrating XProc it might be useful to parse the XPath
expressions anyway, because they sometimes need to be modified in a
non-trivial way. And once you parse them, you can reformat them.
Possibly not at the original locations, but after iteration 2 it will be
idempotent. And that’s what you probably want, an XPath linter within
your XSLT linter.
People I know of who recently parsed XPath 3.1 (with XSLT and probably
also other languages, maybe with REx-generated parsers) are Wendell Piez
and Phil Fearon. Maybe they can point you to a readily available
REx-generated parser in XSLT.
A poor man's solution could be to use string-based preprocessing (be it
unparsed-text() from within XSLT, Perl, ...) in order to substitute
whitespace in the attributes with other characters (maybe from the
private use area), lint the XSLT, and then revert the replacements.
Gerrit
On 28.07.2020 23:17, Willem Van Lishout willemvanlishout(_at_)gmail(_dot_)com
wrote:
Hi list,
Like many of you, I assume, I use a version control system when working
on XSLT projects. I'm working together with multiple people, and we run
the code through an XML formatter before checking it in to avoid
formatting differences showing up in the diffs.
The problem is that, due to attribute value normalization, carriage
returns are removed from attribute nodes during XML parsing. When using
long XPath expressions (and this has become very common in XSLT 3,
especially with higher order functions), which are split in multiple
lines, this results in huge single line outputs which are impossible to
read.
It seems any sort of XML processing will irreversibly transform the
whitespace, therefore I have to choose between:
- No formatting
- Formatting using non-XML tools?
- Finding a parser that bends the rules...
Have any of you experienced the same problem and did you find a solution?
Thanks.
Willem Van Lishout
willemvanlishout(_at_)gmail(_dot_)com
<mailto:willemvanlishout(_at_)gmail(_dot_)com>
XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/225679>
(by email <>)
--~----------------------------------------------------------------
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>
|
- [xsl] Source code formatting, Willem Van Lishout willemvanlishout(_at_)gmail(_dot_)com
- Re: [xsl] Source code formatting,
Imsieke, Gerrit, le-tex gerrit(_dot_)imsieke(_at_)le-tex(_dot_)de <=
- Re: [xsl] Source code formatting, Geert Bormans geert(_at_)gbormans(_dot_)telenet(_dot_)be
- Re: [xsl] Source code formatting, Imsieke, Gerrit, le-tex gerrit(_dot_)imsieke(_at_)le-tex(_dot_)de
- Re: [xsl] Source code formatting, John Lumley john(_at_)saxonica(_dot_)com
- Re: [xsl] Source code formatting, Piez, Wendell A. (Fed) wendell(_dot_)piez(_at_)nist(_dot_)gov
- Re: [xsl] Source code formatting, Imsieke, Gerrit, le-tex gerrit(_dot_)imsieke(_at_)le-tex(_dot_)de
- [Slightly Off Topic] mail server [was: Re: [xsl] Source code formatting], Geert Bormans geert(_at_)gbormans(_dot_)telenet(_dot_)be
- Re: [Slightly Off Topic] mail server [was: Re: [xsl] Source code formatting], Imsieke, Gerrit, le-tex gerrit(_dot_)imsieke(_at_)le-tex(_dot_)de
- Re: [Slightly Off Topic] mail server [was: Re: [xsl] Source code formatting], Piez, Wendell A. (Fed) wendell(_dot_)piez(_at_)nist(_dot_)gov
- Re: [Slightly Off Topic] mail server [was: Re: [xsl] Source code formatting], Peter Flynn peter(_at_)silmaril(_dot_)ie
Re: [xsl] Source code formatting, Dimitre Novatchev dnovatchev(_at_)gmail(_dot_)com
|
|
|