Re: [xsl] How to retain the end tag when outputting an empty element?

Subject: Re: [xsl] How to retain the end tag when outputting an empty element?
From: "Bauman, Syd s.bauman@xxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 17 Jun 2022 17:25:46 -0000
MK> <test></test> is the canonical form. I've no idea why. Perhaps because
it's simpler, in the sense that all elements are serialized the same way
regardless of whether or not they are empty. (With no need for special rules
about edge cases, like elements that are empty except for comments).

I do not know why, either, but I have always presumed exactly the reasons you
state. Why? Because I would do it that way for those reasons.


As for Rogerbs original question, I am fond of lying to my students, telling
them that whether an XML processor writes b<duck/>b or b<duck></duck>b
is up to the processor; since they are the same as far as XML is concerned,
you (the human) do not get to say which you want. (I typically confess this
oversimplification later in the course, explaining that a processor does not
have to give you a choice, but it is welcome to, and some do.)

Using this (admittedly simplified) theory of XML processing, though, the
answer to bhow to get <duck></duck> instead of <duck/>b is
$ perl -pe 's,<([A-Za-z][A-Za-z0-9._-]+)/>,<$1></$1>,g;' < INPUT.xml >
OUTPUT.xml
or similar.

(Where the regular expression I use here is one that will match all TEI
element names without a namespace prefix, and obviously may need to be
adjusted for other use cases.)

Note, of course, that this non-XML solution changes b<!-- do not use
"<blort/>", use "<blort></blort>" instead -->b into the hilariously
difficult to figure out b<!-- do not use "<blort></blort>", use
"<blort></blort>" instead -->b. p


________________________________

Current Thread