formatting XPath expressions in XSLT 3 text templates

Here should go questions about transforming XML with XSLT and FOP.
Martin Honnen
Posts: 52
Joined: Tue Aug 19, 2014 12:04 pm

formatting XPath expressions in XSLT 3 text templates

Post by Martin Honnen » Sat Apr 13, 2019 1:10 pm

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?

adrian
Posts: 2535
Joined: Tue May 17, 2005 4:01 pm

Re: formatting XPath expressions in XSLT 3 text templates

Post by adrian » Tue Apr 16, 2019 3:57 pm

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
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Post Reply