[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: indenting maps on write

Subject: Re: indenting maps on write
From: "Willem Van Lishout willemvanlishout@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 3 Apr 2024 01:43:46 -0000
Re:  indenting maps on write
In my experience, this is hard to get right. It shows that XML attributes
weren't really conceived with the idea to write code in them.

Some ideas:
- Modify the XML parser to not do attribute normalisation (if possible in your
environment)
- Maybe try parsing the map using xsl:evaluate and reconstruct it? Although
then you will probably encounter other issues, e.g. I believe key order is
non-deterministic.
- Use <xsl:map>
- Explain your colleagues how it works and tell them to live with it.

Willem

On 3 Apr 2024, 07:29, at 07:29, "David Carlisle d.p.carlisle@xxxxxxxxx"
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>If you want to force a newline in the serialisation you need to special
>case the newline from the standard xml normalisation, I use @ here but
>any
>character guaranteed not to be in the input would work
>
><?xml version="1.0" encoding="UTF-8"?>
><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>  xmlns:xs="http://www.w3.org/2001/XMLSchema"
>  xmlns:math="http://www.w3.org/2005/xpath-functions/math"
>  xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
>  exclude-result-prefixes="xs math xd"
>  version="3.0">
> <xsl:output use-character-maps="nl"/>
> <xsl:character-map name="nl">
>  <xsl:output-character character="@" string="&#10;"/>
> </xsl:character-map>
>  <xd:doc scope="stylesheet">
>    <xd:desc>
>      <xd:p><xd:b>Created on:</xd:b> Apr 2, 2024</xd:p>
>      <xd:p><xd:b>Author:</xd:b> graydon</xd:p>
>      <xd:p></xd:p>
>    </xd:desc>
>  </xd:doc>
>  <xsl:mode on-no-match="shallow-copy"/>
>  <xd:doc>
>    <xd:desc>increment the instance number</xd:desc>
>  </xd:doc>
><xsl:template match="xsl:variable[@name eq
>'punctuationNameMap']/@select">
>   <xsl:attribute name="select" select="replace(.,' {7}','@      ')"/>
>  </xsl:template>
></xsl:stylesheet>
>
>
>
>On Wed, 3 Apr 2024 at 01:16, David Carlisle d.p.carlisle@xxxxxxxxx <
>xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
>>
>>
>> On Wed, 3 Apr 2024 at 00:28, Graydon graydon@xxxxxxxxx <
>> xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>>
>>> On Tue, Apr 02, 2024 at 09:19:29PM -0000, Michael Kay
>>> michaelkay90@xxxxxxxxx scripsit:
>>> > Well, `file:write` isn't going to add any whitespace, it will be
>some
>>> process prior to that (which you haven't shown us).
>>>
>>> If I boil the whole thing down to a simple example, if I start with:
>>>
>>>
>> so you are adding the space, not the xslt system.
>>
>> In an xml attribute the xml parser will normalise newlines to a space
>so
>> you are adding  9 spaces before each key of the map from a newline
>and 8
>> spaces.
>> You could replace . in replace(.,'''','')  by  normalize-space(.) or
>> replace(.,' ','') depending how aggressively you want to remove
>space.
>>
>> David
>>
>> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
>> EasyUnsubscribe
><http://lists.mulberrytech.com/unsub/xsl-list/2739265> (by
>> email <>)

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.