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
DG SarboSubject: alternative for 'exists'
Author: DG Sarbo
Date: 16 Jul 2009 05:07 AM
When making a mapping, the resulting xml has sometimes (optional) empty segments/tags. Because we want to have 'clean' output, in the mapping these segments are put in a 'exists' function.

Because our organisation uses a lot of mappings with a lot of optional fields ... I am looking for a generic function that filters out the empty segments/tags. Is this possible in xquery? Could anybody point me in the right direction?

Any help would be very welcome!

Postnext
Tony LavinioSubject: alternative for 'exists'
Author: Tony Lavinio
Date: 10 Aug 2009 03:40 PM
There isn't an inline way to do this for everything at once in XQuery,
but there are lots of nice ways to do it between the XML output of
XQuery and the next stage.

For example, inserting this little XSLT filter into the pipeline:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[count(@*) = 0 and count(*) = 0 and normalize-space(.) = '']"/>
</xsl:stylesheet>

will remove every element that satisfies this criteria:
- no child elements
- no attributes
- no text (defined as at least one non-whitespace character)

Postnext
DG SarboSubject: alternative for 'exists'
Author: DG Sarbo
Date: 11 Aug 2009 03:34 AM
Originally Posted: 11 Aug 2009 03:26 AM
Thank you for looking at this issue. This approach seems very interesting but leaves me with a question.

If I use xlst, the XML file is left unchanged?
In other words; we use xml to communicate data to customers. The input is not displayed but put into a database (by our customers). Is xslt able to change the input we send out (change the xml content), or is it primarily used for displaying purposes?

Posttop
Tony LavinioSubject: alternative for 'exists'
Author: Tony Lavinio
Date: 11 Aug 2009 10:07 AM
XSLT and XQuery can both be used in the same fashion - they read
XML, and they write XML.

If you use the XML Pipeline inside of Stylus Studio to connect
the pieces together and then look at the resulting code, you can
see how you can directly chain them.

Or, you can just run the XSLT as a filter on your output before
sending it on.

 
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.