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 8649373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:32:46+00:00 2026-06-12T13:32:46+00:00

I have problem with parsing XML file using XLTS. <html xmlns=http://www.w3.org/1999/xhtml xml:lang=pl> <body style=margin-top:

  • 0

I have problem with parsing XML file using XLTS.

    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl">
    <body style="margin-top: 0px;">
    <a name="top"/>
    <a name="menu"> </a>
    <a href="cool html"> </a>
    <table width="100%" cellspacing="0" cellpadding="2" border="0" class="aws_border sortable"/>
    </body>
    </html>

And I need to delete all node with <a name="something"> </a>, while preserving <a href> nodes and other nodes in document.

I have tried

    <xsl:stylesheet version = '1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
    <xsl:template match="body"> 
    <xsl:for-each select="a"> 
      <xsl:if test="@href != '' ">
     <xsl:copy-of select="."/> 
    </xsl:if>
         </xsl:for-each> 
    </xsl:template>
    </xsl:stylesheet>

But it preserves only <a href > nodes, and deleting all the other nodes.

  • 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-12T13:32:48+00:00Added an answer on June 12, 2026 at 1:32 pm

    Preserving all nodes and changing only a few always goes like this:

    1. You use the identity template. It copies (“preserves”) all nodes that are not handled otherwise.
    2. You write another template for each node that should be handled differently.
    3. You resist the urge to use <xsl:for-each>. You don’t need it.

    XSLT:

    <xsl:stylesheet version="1.0" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:xhtml="http://www.w3.org/1999/xhtml"
    >
    
      <!-- the identity template -->    
      <xsl:template match="@* | node()">
        <xsl:copy>
          <xsl:apply-templates select="@* | node()" />
        </xsl:copy>
      </xsl:template>
    
      <!-- empty template to remove <a name="..."> specifically -->    
      <xsl:template match="xhtml:a[@name]" />
    
    </xsl:stylesheet>
    

    That’s it.

    Point 3 is actually pretty important. Avoid <xsl:for-each> in all XSLT you write. It seems familiar and helpful, but it’s not. Its use tends to result in clunky, monolithic, deeply nested XSLT code that is hard to re-use.

    Always try to prefer <xsl:template> and <xsl:apply-templates> over <xsl:for-each>.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem parsing a XML file which contains special characters like ,
I have an XML document that looks like this: <Data xmlns=http://www.domain.com/schema/data xmlns:dmd=http://www.domain.com/schema/data-metadata > <Something>...</Something>
I have to parse xml file and after parsing I have to out related
I am trying to read an XML file using LINQ. I have had no
I am parsing xml file from url(in code below), using file_get_contents() function, and simpleXML,
I am parsing a XML file in Java using the W3C DOM. I am
hi friends i'm using Sax parser for parsing my xml file which i recieve
I have a process that is parsing an XML file. This is occuring in
I just installed lxml for parsing xml file in python. I am using TextMate
I'm parsing a variety of XML files using jQuery and have implemented a search

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.