cancel
Showing results for 
Search instead for 
Did you mean: 

How to Supress null target Elements in XSLT Mapping

Former Member
0 Kudos

Hi Experts,

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

Accepted Solutions (1)

Accepted Solutions (1)

henrique_pinto
Active Contributor
0 Kudos

Hi Ram,

try to put the tag inside the IF conditions.

It'd be something like:

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

> <a:ENERGY><xsl:value-of select="STRING2"/></a:ENERGY>

> </xsl:if>

> </xsl:if>

> </xsl:for-each>

> </xsl:if>

> </xsl:for-each>

> </xsl:if>

> </xsl:for-each>

Regards,

Henrique.

Former Member
0 Kudos

Hi Henrique,

Thank you very much for your update. Your Answer really helped me in solving the current issue and also it helped me in stoping the reoccouring loops.

Thank you very much.

-Ram

henrique_pinto
Active Contributor
0 Kudos

Cheers

Regards,

Henrique.

Answers (0)