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

  • SEARCH
  • Home
  • 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 926177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:38:32+00:00 2026-05-15T19:38:32+00:00

I have some complex XSLT 2.0 transformations. I’m trying to find out if there

  • 0

I have some complex XSLT 2.0 transformations. I’m trying to find out if there is general purpose way to ensure that no empty tags are output. So… conceptually, a final stage of processing that recursively removes all empty tags. I understand this could be done by a separate XSLT that did nothing but filter out empty tags, but I need to have it all packaged together in a single one.

  • 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-05-15T19:38:33+00:00Added an answer on May 15, 2026 at 7:38 pm

    This XSLT 2.0 transformation illustrates how multi-pass (in this case 2-pass) processing can be done:

    <xsl:stylesheet version="2.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xsl:output omit-xml-declaration="yes" indent="yes"/>
        <xsl:strip-space elements="*"/>
    
     <xsl:template match="node()|@*" mode="#all">
         <xsl:copy>
           <xsl:apply-templates select="node()|@*" mode="#current"/>
         </xsl:copy>
     </xsl:template>
    
     <xsl:template match="/">
       <xsl:variable name="vPass1">
         <xsl:apply-templates/>
       </xsl:variable>
    
       <xsl:apply-templates select="$vPass1/*" mode="non-empty"/>
     </xsl:template>
    
     <xsl:template match="text()[xs:integer(.) mod 2 eq 0]"/>
    
     <xsl:template match="*[not(node())]" mode="non-empty"/>
    </xsl:stylesheet>
    

    when applied on this XML document:

    <nums>
      <num>01</num>
      <num>02</num>
      <num>03</num>
      <num>04</num>
      <num>05</num>
      <num>06</num>
      <num>07</num>
      <num>08</num>
      <num>09</num>
      <num>10</num>
    </nums>
    

    It creates a result document in the first pass (which is captured in the $vPass1 variable), in which all <num> elements with contents even integer are stripped off their content and are empty. Then, in the second pass, applied in a specific mode, all empty elements are removed.

    The result of the transformation is:

    <nums>
       <num>01</num>
       <num>03</num>
       <num>05</num>
       <num>07</num>
       <num>09</num>
    </nums>
    

    Do note the use of modes, and the special modes #all and #current.

    Update: The OP now wants in a comment to delete “recursively” “all nodes that have no non-empty descendant”.

    This can be implemented simpler using no explicit recursion. Just change:

     <xsl:template match="*[not(node())]" mode="non-empty"/>
    

    to:

     <xsl:template match="*[not(descendant::text())]" mode="non-empty"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some complex stored procedures that may return many thousands of rows, and
I have some UI in VB 2005 that looks great in XP Style, but
We have some input data that sometimes appears with &nbsp characters on the end.
I have some classes layed out like this class A { public virtual void
We have some files on our website that users of our software can download.
I have some complex regular expressions which I need to comment for readability and
I have some complex types here so I decided to use nifty trick to
I have some ASP.NET web services which all share a common helper class they
I have some code for starting a thread on the .NET CF 2.0: ThreadStart
I have some C# / asp.net code I inherited which has a textbox which

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.