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