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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
+ XSLT Help and Discussion (7625)
- XQuery Help and Discussion (2017)
-> + Issue with Processing Instruct... (2)
-> + problem converting json to XML... (2)
-> + Problem base64 decoding string... (3)
-> + Problems posting multipart for... (5)
-> + trouble with download of price... (2)
-> + Problem with http-post not bei... (3)
-> + path problem, xps_file:writeAl... (9)
-> + Xquery update support? (2)
-> + problem with Stylus studio try... (5)
-> + adding dtd reference to xml ou... (4)
-> + xquery escaping ambarsand when... (3)
-> + Whitespace problem when return... (5)
-> + Problem with namespace prefix ... (5)
-> - Sending via SFTP returns unexp... (1)
-> + Query and Sftp clent (4)
-> + xquery and try - catch (3)
-> + Query + ddtek:http-post optio... (5)
-> + Example files referenced in do... (3)
-> + Automatic Error Detection and ... (3)
-> + Working with result of ddtek:h... (2)
-- [1-20] [21-40] [41-60] Next
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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).

   
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.