Click here to Skip to main content
12,357,929 members (71,632 online)
Rate this:
Please Sign up or sign in to vote.
See more: XML XSLT
Hello All

I have one issue related to removing tag from xml file while creating it by applying xsl.

<!--START: operation-->
<xsl:element name="operation">
<xsl:if test="string-length(here value of a1 from another xml) > 0">
    <xsl:element name="a1">
       <xsl:value-of select="normalize-space(here value of a1 from another xml); />
<xsl:if test="string-length(here value of a1 from another xml) > 0">

There are number of child tags such as a1,b1,c1,d1 with multiple counts[as shown in example a1] whose value is coming from another Parent XML{whose tags and names are different}. The child elements are created only when the value in another XML i.e. Parent XML is not null.
My issue is i want to remove the operation tag if its child node does not exists.
Note: In this i don't want to apply another XSL for removing the operation tag. As i created the sample application by applying another XSL on the output.xml which is working fine.
the code is use to remove the operation tag if child node does not exists is shown below used in another xsl
<xsl:template match="node()|@*">
      <xsl:apply-templates select="node()|@*"/>
  <xsl:template match="operation[not(a1or b1 or c1 or d1)]"/>
Is there any way by which i can remove the tag by applying only one XSL.

Thanks for helping in advance and waiting for your suggestion.
Posted 30-Jul-12 19:08pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Try this:

<xsl:template match="text()">
    <xsl:variable name="Nod" >
       <xsl:value-of select="local-name(..)" />
    <xsl:variable name="NodValue" >
       <xsl:value-of select="." />
 <xsl:if test="(contains($Nod,'a1') or contains($Nod,'b1') or contains($Nod,'c1') or contains($Nod,'d1')) and NodValue != ''">
  <xsl:value-of select="." />

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 20 Aug 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100