Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: XMLXSLT
Hello All
 
I have one issue related to removing tag from xml file while creating it by applying xsl.
 
e.g:
<!--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:element>
</xsl:if>
<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:element>
</xsl:if>
<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:element>
</xsl:if>
    <!--END: a1-->
</xsl:element>
<!--END: operation-->
 
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:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>
  <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
sagar55885

1 solution

Rate this: bad
good
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>
    <xsl:variable name="NodValue" >
       <xsl:value-of select="." />
    </xsl:variable>
 <xsl:if test="(contains($Nod,'a1') or contains($Nod,'b1') or contains($Nod,'c1') or contains($Nod,'d1')) and NodValue != ''">
  <xsl:value-of select="." />
</xsl:if>
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 680
1 OriginalGriff 379
2 Manas Bhardwaj 350
3 Abhinav S 293
4 Sampath Lokuge 245
0 Sergey Alexandrovich Kryukov 7,647
1 OriginalGriff 4,287
2 Peter Leow 3,681
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 20 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid