Hello --
I'm trying to regularize the formatting of some XSLT files by loading them (via doc()) and writing them back out via file:write()
I know about the *indent* and *indent-attributes* serialization parameters, and mostly they're doing what I want.
What I'd like is to preserve a one-line-per-entry format for a map in a select attribute. For example, I'd like to keep
<xsl:variable as="map(xs:integer,xs:string)" name="hexNum" select=" map { 1: '0', 2: '1', 3: '2', 4: '3', 5: '4', 6: '5', 7: '6', 8: '7', 9: '8', 10: '9', 11: 'a', 12: 'b', 13: 'c', 14: 'd', 15: 'e', 16: 'f' }" static="yes" />
instead of
<xsl:variable as="map(xs:integer,xs:string)" name="hexNum" select=" map { 1: '0', 2: '1', 3: '2', 4: '3', 5: '4', 6: '5', 7: '6', 8: '7', 9: '8', 10: '9', 11: 'a', 12: 'b', 13: 'c', 14: 'd', 15: 'e', 16: 'f' }" static="yes"/>
I don't think there's a way to do this with the serialization parameters, but is there a way to do this?
Thanks! Graydon
Hi Graydon,
This might not be a serialization but a parsing problem The XML parser performs attribute value normalization as per https://www.w3.org/TR/xml/#AVNormalize
I have often wished that there were a parser option to preserve newlines in attribute values, in particular for keeping the indentation of multiline XPath expressions in XProc or XSLT in a future XProc 1.0 → 3.0 migration tool.
For such a migration, the XPath expressions may need modifications, too, so I thought they need to be parsed and transformed anyway, and then they can be re-serialized with indentation (I haven't tried b/c I'm writing this on the phone, but I strongly believe I can have newlines serialized in attribute values).
But in your case a parser option would be useful.
An alternative could be to apply some text preprocessing to the document. For example, read it with unparsed-text, use analyze-string to match attribute values (difficult even in moderately complex cases), replace each newline with a PUA character and serialize this character as newline using a character map later on.
Gerrit
Sent from MailDroid
-----Original Message----- From: Graydon Saunders graydonish@gmail.com To: BaseX BaseX-Talk@mailman.uni-konstanz.de Sent: Fri, 23 Feb 2024 22:50 Subject: [basex-talk] file:write, formatting, and maps in select attributes
Hello --
I'm trying to regularize the formatting of some XSLT files by loading them (via doc()) and writing them back out via file:write()
I know about the *indent* and *indent-attributes* serialization parameters, and mostly they're doing what I want.
What I'd like is to preserve a one-line-per-entry format for a map in a select attribute. For example, I'd like to keep
<xsl:variable as="map(xs:integer,xs:string)" name="hexNum" select=" map { 1: '0', 2: '1', 3: '2', 4: '3', 5: '4', 6: '5', 7: '6', 8: '7', 9: '8', 10: '9', 11: 'a', 12: 'b', 13: 'c', 14: 'd', 15: 'e', 16: 'f' }" static="yes" />
instead of
<xsl:variable as="map(xs:integer,xs:string)" name="hexNum" select=" map { 1: '0', 2: '1', 3: '2', 4: '3', 5: '4', 6: '5', 7: '6', 8: '7', 9: '8', 10: '9', 11: 'a', 12: 'b', 13: 'c', 14: 'd', 15: 'e', 16: 'f' }" static="yes"/>
I don't think there's a way to do this with the serialization parameters, but is there a way to do this?
Thanks! Graydon
Hi Graydon,
I'm trying to regularize the formatting of some XSLT files
I don't think this can or should be done with BaseX serialization. I would use a dedicated formater/ pretty printer. For me the sign of a good formatter is that it tidies random indentation while preserving what looks intentional.
Phil Fearon has done a lot of great work on formatting XML/XSLT [1]. I use his Deltaxml Vscode extension [2] Works for me [3] If Vscode is not a route you want to take, maybe the older standalone xmlspectrum [4] would also work (untested).
/Andy
[1] https://github.com/pgfearo [2] https://marketplace.visualstudio.com/items?itemName=deltaxml.xslt-xpath [3] https://imgur.com/a/E0388Si [3] https://github.com/pgfearo/xmlspectrum
On Fri, 23 Feb 2024 at 23:37, gerrit.imsieke@le-tex.de wrote:
Hi Graydon,
This might not be a serialization but a parsing problem The XML parser performs attribute value normalization as per https://www.w3.org/TR/xml/#AVNormalize
I have often wished that there were a parser option to preserve newlines in attribute values, in particular for keeping the indentation of multiline XPath expressions in XProc or XSLT in a future XProc 1.0 → 3.0 migration tool.
For such a migration, the XPath expressions may need modifications, too, so I thought they need to be parsed and transformed anyway, and then they can be re-serialized with indentation (I haven't tried b/c I'm writing this on the phone, but I strongly believe I can have newlines serialized in attribute values).
But in your case a parser option would be useful.
An alternative could be to apply some text preprocessing to the document. For example, read it with unparsed-text, use analyze-string to match attribute values (difficult even in moderately complex cases), replace each newline with a PUA character and serialize this character as newline using a character map later on.
Gerrit
Sent from MailDroid https://goo.gl/ODgwBb
-----Original Message----- From: Graydon Saunders graydonish@gmail.com To: BaseX BaseX-Talk@mailman.uni-konstanz.de Sent: Fri, 23 Feb 2024 22:50 Subject: [basex-talk] file:write, formatting, and maps in select attributes
Hello --
I'm trying to regularize the formatting of some XSLT files by loading them (via doc()) and writing them back out via file:write()
I know about the *indent* and *indent-attributes* serialization parameters, and mostly they're doing what I want.
What I'd like is to preserve a one-line-per-entry format for a map in a select attribute. For example, I'd like to keep
<xsl:variable as="map(xs:integer,xs:string)" name="hexNum" select=" map { 1: '0', 2: '1', 3: '2', 4: '3', 5: '4', 6: '5', 7: '6', 8: '7', 9: '8', 10: '9', 11: 'a', 12: 'b', 13: 'c', 14: 'd', 15: 'e', 16: 'f' }" static="yes" />
instead of
<xsl:variable as="map(xs:integer,xs:string)" name="hexNum" select=" map { 1: '0', 2: '1', 3: '2', 4: '3', 5: '4', 6: '5', 7: '6', 8: '7', 9: '8', 10: '9', 11: 'a', 12: 'b', 13: 'c', 14: 'd', 15: 'e', 16: 'f' }" static="yes"/>
I don't think there's a way to do this with the serialization parameters, but is there a way to do this?
Thanks! Graydon
-- Graydon Saunders | graydonish@fastmail.com Þæs oferéode, ðisses swá mæg. -- Deor ("That passed, so may this.")
Hi Andy,
Those look like very useful links; thank you!
Absolutely not going to argue it's BaseX's job in particular to have a considered-as-lines consistency default, but keep running into situations where one is needed.
thanks! Graydon
On Sat, Feb 24, 2024 at 8:30 AM Andy Bunce bunce.andy@gmail.com wrote:
Hi Graydon,
I'm trying to regularize the formatting of some XSLT files
I don't think this can or should be done with BaseX serialization. I would use a dedicated formater/ pretty printer. For me the sign of a good formatter is that it tidies random indentation while preserving what looks intentional.
Phil Fearon has done a lot of great work on formatting XML/XSLT [1]. I use his Deltaxml Vscode extension [2] Works for me [3] If Vscode is not a route you want to take, maybe the older standalone xmlspectrum [4] would also work (untested).
/Andy
[1] https://github.com/pgfearo [2] https://marketplace.visualstudio.com/items?itemName=deltaxml.xslt-xpath [3] https://imgur.com/a/E0388Si [3] https://github.com/pgfearo/xmlspectrum
On Fri, 23 Feb 2024 at 23:37, gerrit.imsieke@le-tex.de wrote:
Hi Graydon,
This might not be a serialization but a parsing problem The XML parser performs attribute value normalization as per https://www.w3.org/TR/xml/#AVNormalize
I have often wished that there were a parser option to preserve newlines in attribute values, in particular for keeping the indentation of multiline XPath expressions in XProc or XSLT in a future XProc 1.0 → 3.0 migration tool.
For such a migration, the XPath expressions may need modifications, too, so I thought they need to be parsed and transformed anyway, and then they can be re-serialized with indentation (I haven't tried b/c I'm writing this on the phone, but I strongly believe I can have newlines serialized in attribute values).
But in your case a parser option would be useful.
An alternative could be to apply some text preprocessing to the document. For example, read it with unparsed-text, use analyze-string to match attribute values (difficult even in moderately complex cases), replace each newline with a PUA character and serialize this character as newline using a character map later on.
Gerrit
Sent from MailDroid https://goo.gl/ODgwBb
-----Original Message----- From: Graydon Saunders graydonish@gmail.com To: BaseX BaseX-Talk@mailman.uni-konstanz.de Sent: Fri, 23 Feb 2024 22:50 Subject: [basex-talk] file:write, formatting, and maps in select attributes
Hello --
I'm trying to regularize the formatting of some XSLT files by loading them (via doc()) and writing them back out via file:write()
I know about the *indent* and *indent-attributes* serialization parameters, and mostly they're doing what I want.
What I'd like is to preserve a one-line-per-entry format for a map in a select attribute. For example, I'd like to keep
<xsl:variable as="map(xs:integer,xs:string)" name="hexNum" select=" map { 1: '0', 2: '1', 3: '2', 4: '3', 5: '4', 6: '5', 7: '6', 8: '7', 9: '8', 10: '9', 11: 'a', 12: 'b', 13: 'c', 14: 'd', 15: 'e', 16: 'f' }" static="yes" />
instead of
<xsl:variable as="map(xs:integer,xs:string)" name="hexNum" select=" map { 1: '0', 2: '1', 3: '2', 4: '3', 5: '4', 6: '5', 7: '6', 8: '7', 9: '8', 10: '9', 11: 'a', 12: 'b', 13: 'c', 14: 'd', 15: 'e', 16: 'f' }" static="yes"/>
I don't think there's a way to do this with the serialization parameters, but is there a way to do this?
Thanks! Graydon
-- Graydon Saunders | graydonish@fastmail.com Þæs oferéode, ðisses swá mæg. -- Deor ("That passed, so may this.")
basex-talk@mailman.uni-konstanz.de