XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
david mareSubject: 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?

Postnext
Minollo I.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>

...will generate what you want:

<tag1><tag2></tag2><tag3></tag3></tag1>


Postnext
david mareSubject: forcing empty elements to have full open/close tags
Author: david mare
Date: 18 Nov 2007 11:40 PM
Thanks, that works!

Just as a follow-up question, I don't suppose the Saxon query processor could do a similar thing?

Posttop
Minollo I.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).

 
Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.