Page 1 of 1

formatting XPath expressions in XSLT 3 text templates

Posted: Sat Apr 13, 2019 1:10 pm
by Martin Honnen
Using XML Editor 21.0, build 2019040204, I am struggling to get some nice formatting of XPath expressions in XSLT 3 text templates.

For instance, imagine I have prototyped some XPath code in the XPath builder e.g.

Code: Select all

serialize(array { let $s := ('a', 'b', 'c', 'd') return for-each-pair($s[position() mod 2 = 1], $s[position() mod 2 = 0], function ($s1,$s2) { [$s2, $s1] }) }, map { 'method'  :  'json', 'indent' : true() })
and now open a new XQuery file and paste that code and use the format and indent button I get a nice formatting and indentation (although the indentation seems to get lost here in the forum when pasting into a code BB block):

Code: Select all


serialize(array {
let $s := ('a', 'b', 'c', 'd')
return
for-each-pair($s[position() mod 2 = 1], $s[position() mod 2 = 0], function ($s1, $s2) {
[$s2, $s1]
})
}, map {
'method': 'json',
'indent': true()
})
However, when I create a new XSLT 3 document and paste the expression into a text template and use the format and indent button I get some rather messy result, the XPath expression is not formatted well:

Code: Select all


<?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" exclude-result-prefixes="xs math"
version="3.0">

<xsl:template name="xsl:initial-template">{serialize(array { let $s := ('a', 'b', 'c', 'd')
return for-each-pair($s[position() mod 2 = 1], $s[position() mod 2 = 0], function ($s1,$s2)
{ [$s2, $s1] }) }, map { 'method' : 'json', 'indent' : true() })}</xsl:template>
</xsl:stylesheet>
Is there some way to get a better formatting and indentation of XPath expressions in XSLT text templates?

Re: formatting XPath expressions in XSLT 3 text templates

Posted: Tue Apr 16, 2019 3:57 pm
by adrian
Hi,

In short, there isn't. The XSLT formatter does not format XPath expressions from text templates on multiple lines, it just wraps the line at the line limit.
I've logged an improvement request.

Regards,
Adrian