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
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Dan PaulSubject: Strip Empty Elements and Attributes but leave Elements with populated attributes
Author: Dan Paul
Date: 03 Mar 2007 11:41 AM
I'm trying to strip empty elements and empty attributes from a document but leave in elements that are empty but have attributes that are populated. So far I've got the following code which removes all elements even if they have attributes populated. How do I add a conditions so something like <employee id="60"/> does not get stripped?

Thanks,
Dan


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:strip-space elements="*"/>

<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*[.='']"/>
<xsl:template match="*[not(node())]"/>

</xsl:stylesheet>

Posttop
(Deleted User) Subject: Strip Empty Elements and Attributes but leave Elements with populated attributes
Author: (Deleted User)
Date: 05 Mar 2007 12:05 PM
Hi Dan,
you can try changing the template to be

<xsl:template match="*[not(node()) and not(@*[.!=''])]"/>

so that elements that don't have text are stripped only if they don't have a non-empty attribute.

Hope this helps,
Alberto

 
Topic Page 1 2 3 4 5 6 7 8 9 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.