Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8355941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:01:12+00:00 2026-06-09T10:01:12+00:00

In the past I have removed empty tags using a separate transform as shown

  • 0

In the past I have removed empty tags using a separate transform as shown below, but now I must do it within the same XSLT 2.0 transform.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
    <xsl:strip-space elements="*" />
    <xsl:template match="*[not(node()) and not(./@*)]"/>
    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

Given this XML, I want to remove all empty tags from the policy node. The XML is can be up to 40 MB or so:

<?xml version="1.0" encoding="UTF-8"?>
<myroot>
    <data>
        <data1>abc</data1>
        <data2>123</data2>
    </data>
    <policy>
        <policydata1>Hello World!</policydata1>
        <policydata2/>
    </policy>
</myroot>

My thought is using XSLT 2.0 I can retain the output of the transform that pertains to the policy node in a variable defined as an ‘element’ so I can treat it like XML and then iterate over the variable to remove the empty tags:

    <xsl:variable name="completepolicy" as="element()">
       <policy>
         <policydata1>Hello World!</policydata1>
         <policydata2/>
       </policy>
   </xsl:variable>

The answer of how to incorporate the tag removal within the variable without affecting the rest of the templates in my transform seems to be escaping me. Can you help me with what is probably obvious?

NOTE the reason I am proposing a variable around the ‘policy’ output is that I already have it declared due to a need to extract some messages from the transform for output elsewhere.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:01:14+00:00Added an answer on June 9, 2026 at 10:01 am

    Just use your original transformation, but replace:

    <xsl:template match="*[not(node()) and not(./@*)]"/>
    

    with:

    <xsl:template match="policy/*[not(node()) and not(@*)]"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the past I have worked with the microchip PIC family, but I would
I haven't searched real hard recently but in the past I have searched high
I have been trying for the past two days now to implement Admob ads
I am new to using Microsoft development tools but have been using Visual Studio
This must have annoyed someone in the past so excuse me if this is
In the past I have used MAPISendMail to launch Outlook (or whatever the desired
In the past I have used Managed Direct X and DirectShow.Net to play a
In the past I have stored database credentials (username, password) in another file (outside
I have question regarding the use of function parameters. In the past I have
Excuse my limited knoweldge here. In the past I have used Steve Sanderson's method

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.