Subject:forcing empty elements to have full open/close tags Author:david mare Date:16 Nov 2007 09:08 PM
Is there any way to force XQuery to output a open/close pair of tags eg. <mytag></mytag> when an element is empty, rather than the abbreviated form <mytag/>
For example: if my input document is:
<root>
<tag1>foo</tag1>
<tag2></tag2>
</root>
And I query this document using this XQuery:
/root
The result is:
<root>
<tag1>foo</tag1>
<tag2/>
</root>
I need to preserve the empty element as <tag2></tag2>
How can I do this? Is there an output format directive or something I could use?
Subject:forcing empty elements to have full open/close tags Author:Minollo I. Date:17 Nov 2007 08:28 AM
David,
from the XML infoset point of view there is absolutely no difference between <tag2/> and <tag2></tag2>; that's why the serialization specs for XQuery 1.0 and XSLT 2.0 don't say anything about that when generating XML (http://www.w3.org/TR/xslt-xquery-serialization/)
The only case in which the serialization specs deal with minimized tag format is when XHTML (http://www.w3.org/TR/xslt-xquery-serialization/#xhtml-output) is used as the output method (just to keep compatibility with HTML browser behaviors). And that should help you; using DataDirect XQuery as the XQuery processor, this:
declare option ddtek:serialize "method=xhtml";
<tag1><tag2/><tag3></tag3></tag1>
Subject:forcing empty elements to have full open/close tags Author:Minollo I. Date:18 Nov 2007 11:50 PM
Yes, it does; you'll need to use:
declare option saxon:output "method=xhtml";
BTW, you'll be able to see that only using the Saxon API directly, not from inside Stylus Studio (as Stylus intercepts the output for debugging/backmapping purposes, and serializes it ignoring the XHTML directive).