Re: [basex-talk] file:write, formatting, and maps in select attributes

2024-02-24 Thread Graydon Saunders
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  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,  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 
>>
>> -Original Message-
>> From: Graydon Saunders 
>> To: BaseX 
>> 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
>>
>> 
>>
>> instead of
>>
>> > 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  | graydon...@fastmail.com
>> Þæs oferéode, ðisses swá mæg.
>> -- Deor  ("That passed, so may this.")
>>
>


Re: [basex-talk] file:write, formatting, and maps in select attributes

2024-02-24 Thread Andy Bunce
 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,  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 
>
> -Original Message-
> From: Graydon Saunders 
> To: BaseX 
> 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
>
> 
>
> instead of
>
>  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  | graydon...@fastmail.com
> Þæs oferéode, ðisses swá mæg.
> -- Deor  ("That passed, so may this.")
>


Re: [basex-talk] file:write, formatting, and maps in select attributes

2024-02-23 Thread gerrit . imsieke
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 
To: BaseX 
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



instead of



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  | graydon...@fastmail.com
Þæs oferéode, ðisses swá mæg.
-- Deor  ("That passed, so may this.")