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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:51:00+00:00 2026-05-30T10:51:00+00:00

I am currently trying to copy out an XML document into a new one

  • 0

I am currently trying to copy out an XML document into a new one and renaming some of the nodes as I go. My issue however is that my templates are not being hit and only the global one is:

  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>

and my specific template is (adapted for below):

  <xsl:template match="F">
    <G>
      <xsl:apply-templates/>
    </G>
  </xsl:template>

The xml structure is similar to this however adapted due to the nature of the work 🙂

<T>
 <A>
  <B>
  </B>
  <C>
  </C>
 </A>
 <D>
  <E>Data</E>
  <F>Data</F>
 </D>
</T>

When running this through in VS2010 I can see it hit the line of F on the XML however is still applies the general template and not the more specific one. Any ideas why this would be?

  • 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-30T10:51:02+00:00Added an answer on May 30, 2026 at 10:51 am

    This OP has conceiled the most important fact about the XML document — as he tells us in a later comment, “The XML uses a namespace” …

    Here is a solution to this so late-clarified question:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:x="some:namespace" xmlns="some:namespace"
     exclude-result-prefixes="x">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:template match="node()|@*">
         <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
         </xsl:copy>
     </xsl:template>
    
     <xsl:template match="x:F">
         <G>
           <xsl:apply-templates/>
         </G>
     </xsl:template>
    </xsl:stylesheet>
    

    when this transformation is applied on the following XML document (based on the namespace the OP admitted…):

    <T xmlns="some:namespace">
        <A>
            <B>   </B>
            <C>   </C>
        </A>
        <D>
            <E>Data</E>
            <F>Data</F>
        </D>
    </T>
    

    the wanted, correct result is produced:

    <T xmlns="some:namespace">
        <A>
            <B />
            <C />
        </A>
        <D>
            <E>Data</E>
            <G>Data</G>
        </D>
    </T>
    

    Explanation:

    The problem in the original code is here:

      <xsl:template match="F">
    

    This template matches an element F that is in no namespace. However all elements of the real XML document are in some undisclosed namespace — not in no namespace. Therefore, the above template cannot match an F element in no namespace, because no such (F element in no namespace) exists.

    The solution is to define the same namespace in the XSLT transformation and to have the template match an F element in that namespace.

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

Sidebar

Related Questions

I'm new to heroku and currently trying to check out a copy of an
I'm currently trying to read in an XML file, make some minor changes (alter
I am currently trying to copy an array I have to a new view
Hey all, I am trying to find out how to copy data from one
I currently trying to find a solution, how to ensure that a test fails
I'm currently trying out db4o (the java version) and I pretty much like what
I'm currently trying to get into the Java EE development with the Spring framework.
I'm currently trying to debug a customer's issue with an FTP upload feature in
I am currently experimenting on some usage of stl-datastructures. However I am still not
I'm trying to learn to use vimdiff well. Currently I figured out how to

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.