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)
-> + How to set a marker for paper ... (2)
-> + Not equality Function (2)
-> + Counting Elements (4)
-> + Looking for help or code samp... (2)
-> + Help needed in pattern matchin... (2)
-> + Repeaters and Ifs (2)
-> + select adjacent nodes in xpath... (3)
-> - Stripping of Empty Target Elem... (2)
-> ->Stripping of Empty Target...
-> + auto-generate Edifact Intercha... (5)
-> + Qname Error in xsl:element (2)
-> + [Newbie] Type conversion and f... (2)
-> + Do ...when (2)
-> + Using Key (3)
-> + sorting elements in option (2)
-> + NaN(not available) value repla... (3)
-> + infinite loop error when tryin... (9)
-> + Escape a character in the stri... (3)
-> + find sum of 2 elements in xml (2)
-> + placing a ' * ' by reading the... (3)
-> + Problem in dispaying Current D... (4)
-- Previous [421-440] [441-460] [461-480] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
Ramachandra Dileep DANNAPANENISubject: Stripping of Empty Target Elements
Author: Ramachandra Dileep DANNAPANENI
Date: 29 Jan 2009 05:41 AM
Hi Team,

I have got a requirement, I need to Strip off (remove) Null tags from my ouput XML document.

My XSLT Mapping file

<?xml version='1.0' ?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<a:A2ACU>
<a:PartNo>
<xsl:value-of select="Specifications/Specification/PARTNO"/>
</a:PartNo>
<a:Revision>
<xsl:value-of select="Specifications/Specification/REVISION"/>
</a:Revision>
<a:ENERGY>
<xsl:for-each select="Specifications/Specification/Section">
<xsl:variable name="Sec_ID">
<xsl:value-of select="SECTIONID"/>
</xsl:variable>
<xsl:if test="$Sec_ID = '700015'">
<xsl:for-each select="Item">
<xsl:variable name="Item_ID">
<xsl:value-of select="ITEMID"/>
</xsl:variable>
<xsl:if test="$Item_ID = '701134'">
<xsl:for-each select="PropertyGroup/Property">
<xsl:variable name="Pro_ID">
<xsl:value-of select="PROPERTYID"/>
</xsl:variable>
<xsl:if test="$Pro_ID = '700232'">
<xsl:variable name="Atr_ID">
<xsl:value-of select="ATTRIBUTEID"/>
</xsl:variable>
<xsl:if test="$Atr_ID = '700064'">
<xsl:value-of select="STRING2"/>
</xsl:if>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</a:ENERGY>
</a:A2ACU>
</xsl:template>
</xsl:stylesheet>

If any one of the condition in ENRGY TAG FAILS it is giving a output as

- <A2ACU>
<PartNo>123456789</PartNo>
<Revision>2</Revision>
<ENERGY></ENERGY>
- </A2ACU>

But as per my new requirement I need to check the Empty value in all the tags and need to strip of them form final output ...like..

- <A2ACU>
<PartNo>123456789</PartNo>
<Revision>2</Revision>
- </A2ACU>

Can any one please suggest me whether any function is availble to this stripping

Thanks in Advance
Ram









Posttop
John BamptonSubject: Stripping of Empty Target Elements
Author: John Bampton
Date: 06 Feb 2009 08:22 AM
For quality XSL consulting email jbampton@gmail.com with XSL as the subject.

Based on this snippet of XML:

<?xml version="1.0" encoding="UTF-8"?>
<A2ACU>
<PartNo>123456789</PartNo>
<Revision>2</Revision>
<ENERGY/>
</A2ACU>

The solution is:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="/">
<A2ACU>
<xsl:if test="A2ACU/PartNo[node()]">
<PartNo>
<xsl:value-of select="A2ACU/PartNo/text()"></xsl:value-of>
</PartNo>
</xsl:if>
<xsl:if test="A2ACU/Revision[node()]">
<Revision>
<xsl:value-of select="A2ACU/Revision/text()"></xsl:value-of>
</Revision>
</xsl:if>
<xsl:if test="A2ACU/ENERGY[node()]">
<ENERGY>
<xsl:value-of select="A2ACU/ENERGY/text()"></xsl:value-of>
</ENERGY>
</xsl:if>
</A2ACU>
</xsl:template>
</xsl:stylesheet>

   
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.