Re: [xml] empty tag


-----Original Message-----
From: xml-bounces gnome org [mailto:xml-bounces gnome org] On 
Behalf Of Daniel Veillard

On Thu, Jul 06, 2006 at 10:55:40PM -0500, Alex Neblett wrote:

Somewhat related, is it possible to preserve <tag></tag> 
rather than have it
convert to <tag/> when doing an xslt tranform?

  No, they are not distinguishable once parsed, they have 
exactly the same
data model, it's actually something clearly stated in the XML-1.0 spec

I am using libexslt to transform xml into xhtml.

Sadly, the consumer of the xhtml content (to which I do not 
have source code
access) is issued and sometimes interprets <tag/> as <tag> then
"autocorrects" the xhtml by inserting a </tag> where it 
deems appropriate
causing all sorts of issues.

  Their application is not XML compliant, too bad they didn't ask for
something compliant to the standard. Note that libxml2 
XHTML-1 serializer
do use <br /> and other crazy suggestions to workaround 
non-XML aware clients
make sure you are outputting the XHTML-1 doctype and libxml2 
will take care of

Presently, I do a second xslt transform to place comments 
inside empty tags
resulting in <tag><!-- DELETE THIS --></tag> as a poor workaround.

Probably, I am not the first person to encounter this 
problem and am also
open to alternative suggestions as to how to solve this issue.

  Yup, that's poor, unfortunately there is no magic spell. 
Have you tried
inserting an empty text node, I think that should be 
sufficient to fool 
libxml2 serializer and force an end tag. However at the XSLT 
level I'm not sure
<xsl:text/> will really do what you want, it might be optimized out.
  XML recommendation was issued in 1998, 8 years ago, if they 
still use
non-compliant tools, then as your customer they force you to 
develop custom
code, hence more expensive I assume, make them pay the 
difference, they
will end up fixing their stack eventually.


The trick with inserting an empty text node won't work anymore
in the next release of Libxslt.
There should be no way on the XSLT side to manipulate
the serialization here. Saxon and MS .NET cannot be fooled by
inserting an empty text node but MSXML 4.0 and Xalan behave
like Libxslt does currently.

This is a serialization issue, and should be handled by customizing
the serialization; if it's possible to customize the serialization
with Libxslt is an other question.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]