Sometimes indentation seems to fail because the document already contains whitespace between the elements which the indentation - correctly - does not touch, resulting in irregular indentation. In order to exclude this source of confusion, I would remove the whitespace between elements and apply indentation to the result. For example, this query removes the critical whitespace: declare function local:pretty($n as node()) { typeswitch($n) case document-node() return document {$n/node() ! local:pretty(.)} case element() return element {node-name($n)} {$n/(@*|node()) ! local:pretty(.)} case text() return $n[not(../*) or matches(.,'\S')] default return $n};./local:pretty(.)
With kind regards,Hans-Jürgen Am Donnerstag, 17. November 2022 um 16:52:32 MEZ hat Jonathan Robie jonathan.robie@gmail.com Folgendes geschrieben:
Using Martin's simple example, I get the same results he does without explicitly declaring the namespace: declare option output:method 'xml'; declare option output:indent 'yes';
<root><foo>bar</foo></root>
=>
<root> <foo>bar</foo> </root> Without the declaration, it's not indented: <root><foo>bar</foo></root>
=>
<root><foo>bar</foo></root> But the indentation is quite different from what I see in Saxon or oXygen output when I indent. You see this with more complex examples. For instance, here it is an excerpt for a book from the New Testament:
declare option output:method 'xml'; declare option output:indent 'yes';
/
=>
<book id="JHN"> <sentence> <p> <milestone unit="verse" id="JHN 1:1">JHN 1:1</milestone> Ἐν ἀρχῇ ἦν ὁ Λόγος, καὶ ὁ Λόγος ἦν πρὸς τὸν Θεόν, καὶ Θεὸς ἦν ὁ Λόγος.</p> <wg> <wg role="g" class="group" xml:id="n430010010010170" rule="Conj3CL"> <wg class="cl" xml:id="n430010010010050" head="true" rule="P-VC-S"> <!--local:clause(), else--> <wg role="p" class="pp" xml:id="n430010010010020" head="true" rule="PrepNp"> <!--Role created from pp2P--> <w ref="JHN 1:1!1" after=" " class="prep" xml:id="n43001001001" lemma="ἐν" normalized="Ἐν" strong="1722" gloss="In [the]" domain="067002" ln="67.33" morph="PREP" unicode="Ἐν">Ἐν</w> <wg class="np" xml:id="n430010010020011" head="true" rule="N2NP"> <w ref="JHN 1:1!2" after=" " class="noun" type="common" xml:id="n43001001002" lemma="ἀρχή" normalized="ἀρχῇ" strong="746" number="singular" gender="feminine" case="dative" head="true" gloss="beginning" domain="067003" ln="67.65" morph="N-DSF" unicode="ἀρχῇ">ἀρχῇ</w> </wg> </wg> <wg role="vc" class="vp" xml:id="n430010010030011" rule="V2VP"> <!--Role created from vp2VC--> <w ref="JHN 1:1!3" after=" " class="verb" xml:id="n43001001003" lemma="εἰμί" normalized="ἦν" strong="1510" number="singular" person="third" tense="imperfect" voice="active" mood="indicative" gloss="was" domain="013003" ln="13.69" morph="V-IAI-3S" unicode="ἦν">ἦν</w> </wg> <wg role="s" class="np" xml:id="n430010010040020" articular="true" rule="DetNP"> <!--Role created from Np2S--> <w ref="JHN 1:1!4" after=" " class="det" xml:id="n43001001004" lemma="ὁ" normalized="ὁ" strong="3588" number="singular" gender="masculine" case="nominative" gloss="the" domain="092004" ln="92.24" morph="T-NSM" unicode="ὁ">ὁ</w> <wg class="np" xml:id="n430010010050011" head="true" rule="N2NP"> <w ref="JHN 1:1!5" after="," class="noun" type="common" xml:id="n43001001005" lemma="λόγος" normalized="Λόγος" strong="3056" number="singular" gender="masculine" case="nominative" head="true" gloss="Word" domain="033006" ln="33.100" morph="N-NSM" unicode="Λόγος,">Λόγος</w> </wg> </wg> </wg> With Saxon or oXygen, I get this: <book id="JHN"> <sentence> <p> <milestone unit="verse" id="JHN 1:1">JHN 1:1</milestone> Ἐν ἀρχῇ ἦν ὁ Λόγος, καὶ ὁ Λόγος ἦν πρὸς τὸν Θεόν, καὶ Θεὸς ἦν ὁ Λόγος.</p> <wg> <wg role="g" class="group" xml:id="n430010010010170" rule="conj3cl"> <wg class="cl" xml:id="n430010010010050" head="true" rule="P-VC-S"><!--local:clause(), else--> <wg role="p" class="pp" xml:id="n430010010010020" head="true" rule="PrepNp"><!--Role created from pp2P--> <w ref="JHN 1:1!1" after=" " class="prep" xml:id="n43001001001" lemma="ἐν" normalized="Ἐν" strong="1722" gloss="In [the]" domain="067002" ln="67.33" morph="PREP" unicode="Ἐν">Ἐν</w> <wg class="np" xml:id="n430010010020011" head="true" rule="N2NP"> <w ref="JHN 1:1!2" after=" " class="noun" type="common" xml:id="n43001001002" lemma="ἀρχή" normalized="ἀρχῇ" strong="746" number="singular" gender="feminine" case="dative" head="true" gloss="beginning" domain="067003" ln="67.65" morph="N-DSF" unicode="ἀρχῇ">ἀρχῇ</w> </wg> </wg> <wg role="vc" class="vp" xml:id="n430010010030011" rule="V2VP"><!--Role created from vp2VC--> <w ref="JHN 1:1!3" after=" " class="verb" xml:id="n43001001003" lemma="εἰμί" normalized="ἦν" strong="1510" number="singular" person="third" tense="imperfect" voice="active" mood="indicative" gloss="was" domain="013003" ln="13.69" morph="V-IAI-3S" unicode="ἦν">ἦν</w> </wg> <wg role="s" class="np" xml:id="n430010010040020" articular="true" rule="DetNP"><!--Role created from Np2S--> <w ref="JHN 1:1!4" after=" " class="det" xml:id="n43001001004" lemma="ὁ" normalized="ὁ" strong="3588" number="singular" gender="masculine" case="nominative" gloss="the" domain="092004" ln="92.24" morph="T-NSM" unicode="ὁ">ὁ</w> <wg class="np" xml:id="n430010010050011" head="true" rule="N2NP"> <w ref="JHN 1:1!5" after="," class="noun" type="common" xml:id="n43001001005" lemma="λόγος" normalized="Λόγος" strong="3056" number="singular" gender="masculine" case="nominative" head="true" gloss="Word" domain="033006" ln="33.100" morph="N-NSM" unicode="Λόγος,">Λόγος</w> </wg> </wg> </wg> <w ref="JHN 1:1!6" after=" " class="conj" xml:id="n43001001006" lemma="καί" normalized="καί" strong="2532" gloss="and" domain="089017" ln="89.93" morph="CONJ" unicode="καὶ">καὶ</w> <wg class="cl" xml:id="n430010010070060" articular="true" rule="S-VC-P"><!--local:clause(), else--> <wg role="s" class="np" xml:id="n430010010070020" articular="true" rule="DetNP"><!--Role created from Np2S--> <w ref="JHN 1:1!7" after=" " class="det" xml:id="n43001001007" lemma="ὁ" normalized="ὁ" strong="3588" number="singular" gender="masculine" case="nominative" gloss="the" domain="092004" ln="92.24" morph="T-NSM" unicode="ὁ">ὁ</w> <wg class="np" xml:id="n430010010080011" head="true" rule="N2NP"> <w ref="JHN 1:1!8" after=" " class="noun" type="common" xml:id="n43001001008" lemma="λόγος" normalized="Λόγος" strong="3056" number="singular" gender="masculine" case="nominative" head="true" gloss="Word" domain="033006" ln="33.100" morph="N-NSM" unicode="Λόγος">Λόγος</w> </wg> </wg> <wg role="vc" class="vp" xml:id="n430010010090011" rule="V2VP"><!--Role created from vp2VC--> <w ref="JHN 1:1!9" after=" " class="verb" xml:id="n43001001009" lemma="εἰμί" normalized="ἦν" strong="1510" number="singular" person="third" tense="imperfect" voice="active" mood="indicative" gloss="was" domain="085001" ln="85.1" morph="V-IAI-3S" unicode="ἦν">ἦν</w> </wg> <wg role="p" class="pp" xml:id="n430010010100030" articular="true" head="true" rule="PrepNp"><!--Role created from pp2P--> <w ref="JHN 1:1!10" after=" " class="prep" xml:id="n43001001010" lemma="πρός" normalized="πρός" strong="4314" gloss="with" domain="089020" ln="89.112" morph="PREP" unicode="πρὸς">πρὸς</w> <wg class="np" xml:id="n430010010110020" articular="true" head="true" rule="DetNP"> <w ref="JHN 1:1!11" after=" " class="det" xml:id="n43001001011" lemma="ὁ" normalized="τόν" strong="3588" number="singular" gender="masculine" case="accusative" gloss="-" domain="092004" ln="92.24" morph="T-ASM" unicode="τὸν">τὸν</w> <wg class="np" xml:id="n430010010120011" head="true" rule="N2NP"> <w ref="JHN 1:1!12" after="," class="noun" type="common" xml:id="n43001001012" lemma="θεός" normalized="Θεόν" strong="2316" number="singular" gender="masculine" case="accusative" head="true" gloss="God" domain="012001" ln="12.1" morph="N-ASM" unicode="Θεόν,">Θεόν</w> </wg> </wg> </wg> </wg> <w ref="JHN 1:1!13" after=" " class="conj" xml:id="n43001001013" lemma="καί" normalized="καί" strong="2532" gloss="and" domain="089017" ln="89.92" morph="CONJ" unicode="καὶ">καὶ</w> <wg class="cl" xml:id="n430010010140040" rule="P-VC-S"><!--local:clause(), else--> <wg role="p" class="np" xml:id="n430010010140011" head="true" rule="N2NP"><!--Role created from Np2P--> <w ref="JHN 1:1!14" after=" " class="noun" type="common" xml:id="n43001001014" lemma="θεός" normalized="Θεός" strong="2316" number="singular" gender="masculine" case="nominative" head="true" gloss="God" domain="012001" ln="12.1" morph="N-NSM" unicode="Θεὸς">Θεὸς</w> </wg> <wg role="vc" class="vp" xml:id="n430010010150011" rule="V2VP"><!--Role created from vp2VC--> <w ref="JHN 1:1!15" after=" " class="verb" xml:id="n43001001015" lemma="εἰμί" normalized="ἦν" strong="1510" number="singular" person="third" tense="imperfect" voice="active" mood="indicative" gloss="was" domain="058010" ln="58.67" morph="V-IAI-3S" unicode="ἦν">ἦν</w> </wg> <wg role="s" class="np" xml:id="n430010010160020" articular="true" rule="DetNP"><!--Role created from Np2S--> <w ref="JHN 1:1!16" after=" " class="det" xml:id="n43001001016" lemma="ὁ" normalized="ὁ" strong="3588" number="singular" gender="masculine" case="nominative" gloss="the" domain="092004" ln="92.24" morph="T-NSM" unicode="ὁ">ὁ</w> <wg class="np" xml:id="n430010010170011" head="true" rule="N2NP"> <w ref="JHN 1:1!17" after="." class="noun" type="common" xml:id="n43001001017" lemma="λόγος" normalized="Λόγος" strong="3056" number="singular" gender="masculine" case="nominative" head="true" gloss="Word" domain="033006" ln="33.100" morph="N-NSM" unicode="Λόγος.">Λόγος</w> </wg> </wg> </wg> </wg> </wg> </sentence>
On Thu, Nov 17, 2022 at 8:36 AM Martin Honnen martin.honnen@gmx.de wrote:
Am 11/17/2022 um 2:29 PM schrieb Giuseppe G. A. Celano:
it is:
declare option output:method 'xml'; declare option output:indent 'yes’;
doc(“myfile.xml”)
How/where are you running that code? In the BaseX GUI? There I get an indented output with similar code.