Re: [xml] empty tag



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

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
it.

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.

Daniel

-- 
Daniel Veillard      | Red Hat http://redhat.com/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



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