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
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>

 
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.