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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:06:20+00:00 2026-05-10T20:06:20+00:00

I am trying something very simple, but for some reason it does not work.

  • 0

I am trying something very simple, but for some reason it does not work. Basically, I need to rename some nodes in an XML document. Thus, I created an XSLT file to do the transformation.

Here is an example of the XML:

EDIT: Addresses and Address elements occur at many levels. This is what caused me to have to try and apply an XSLT. The Visual Studio typed dataset feature, which creates typed datasets from XSD files does not permit you to have nested references to the same table. Thus, having Businesses/Business/Addresses and Businesses/Business/Contact/Addresses causes the Load() to fail. This is a known issue, and all they tell you is something like ‘Don’t have nested table references…edit your XSD to stop having that.’ Unfortunately, this means that we have to apply XSLT to make the XML conform to the ‘hacked’ XSD, since the files are coming from a third party vendor.

So, we are very close with the help rendered here. The last couple of things are these:

1.) How can I use the namespace reference in the match attribute of the xsl:template in order to specify that I want to rename Businesses/Business/Addresses to BusinessAddresses, but rename Businesses/Business/Contacts/Contact/Addresses to ContactAddresses?

2.) How can I stop the XSLT from cluttering every new element with explicit namespace references? It is causing extreme bloat in the output.

I created a namespace called ‘steel’, and was having good success with:

<xsl:template match='steel:Addresses>   <xsl:element name='BusinessAddresses> </xsl:template> 

The obvious problem here is that it renames ALL of the Addresses elements to BusinessAddresses, even though I want some of them named ContactAddresses, and so on. The needless addition of explicit namespace references to all of the renamed nodes is also troublesome.

I tried this sort of thing, but as soon as I add slashes to the match attribute, it is a a syntax error in the XSLT, like so:

<xsl:template match='steel:/Businesses/Business/Addresses'> 

I feel very close, but need some guidance on how to mix both the namespace usage and a way to use the slashes to select ANY nodes under specific paths.

<?xml version='1.0'?> <Businesses>   <Business>     <BusinessName>Steel Stretching</BusinessName>     <Addresses>       <Address>         <City>Pittsburgh</City>       </Address>       <Address>         <City>Philadelphia</City>       </Address>     </Addresses>     <Contacts>       <Contact>         <FirstName>Paul</FirstName>         <LastName>Jones</LastName>         <Addresses>           <Address>             <City>Pittsburgh</City>           </Address>         </Addresses>       </Contact>     </Contacts>   </Business>   <Business>     <BusinessName>Iron Works</BusinessName>     <Addresses>       <Address>         <City>Harrisburg</City>       </Address>       <Address>         <City>Lancaster</City>       </Address>     </Addresses>   </Business> </Businesses> 

I need to rename Addresses to BusinessAddresses, and I need to rename Address to BusinessAddress, for every instance of Addresses and Address directly under a Business node. I also need to rename Addresses to ContactAddresses, and I need to rename Address to ContactAddress, for every instance of Addresses and Address directly under a Contact Node.

I have tried several solutions, but none seem to work. They all end up producing the same XML as the original file.

Here is an example of what I have tried:

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

This has been tried in at least 6 different flavors, complete with stepping through the XSLT debugger in VB.Net. It never executes the template match for Addresses.

Why?

  • 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. 2026-05-10T20:06:20+00:00Added an answer on May 10, 2026 at 8:06 pm

    Why might an XSLT fail?

    An XSLT will fail because of obvious things like typos. However, the most likely situation relates to namespace usage. If you declared a default namespace for your XML but don’t include that in your XSLT, the XSLT won’t match the templates as you might expect.

    The following example adds the xmlns:business attribute which declares that items qualified by the business prefix belong to the namespace mynamespace.uri. I then used this prefix to qualify the Address and Addresses template matches. Of course, you will need to change the namespace URI to whatever matches the default namespace of your XML file.

    <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'                 xmlns:msxsl='urn:schemas-microsoft-com:xslt'                 xmlns:business='mynamespace.uri'                 exclude-result-prefixes='msxsl'>   <xsl:template match='/'>     <xsl:apply-templates select='@*|node()'/>   </xsl:template>    <xsl:template match='@*|node()'>     <xsl:copy>       <xsl:apply-templates select='@*|node()'/>     </xsl:copy>   </xsl:template>    <xsl:template match='business:Addresses'>     <xsl:element name='BusinessAddresses'>       <xsl:apply-templates select='@*|node()' />     </xsl:element>   </xsl:template>    <xsl:template match='business:Address'>     <xsl:element name='BusinessAddress'>       <xsl:apply-templates select='@*|node()'/>     </xsl:element>   </xsl:template> </xsl:stylesheet> 

    How do you match templates based on element location as well as name?

    There are several ways to achieve this last part to your problem, BusinessAddress or ContactAddress, but the easiest is to modify the template match attributes to consider parent nodes. If you think of the match attribute as a path into the XML for a node, this option becomes clearer (contents of templates left out for brevity):

    <xsl:template match='business:Business/business:Addresses> </xsl:template>  <xsl:template match='business:Business/business:Addresses/business:Address'> </xsl:template>  <xsl:template match='business:Contact/business:Addresses'> </xsl:template>  <xsl:template match='business:Contact/business:Addresses/business:Address'> </xsl:template> 

    Other methods exist for achieving this if the match remains based on just the element name, but they’re harder to implement, follow, and maintain as they involve the use of conditional checks on the parent node hierarchy of the element being processing, all within the template.

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

Sidebar

Ask A Question

Stats

  • Questions 52k
  • Answers 52k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer For all intents and purposes, I believe that the output… May 11, 2026 at 6:37 am
  • added an answer Ok, I see, I expressed myself not clearly. I know… May 11, 2026 at 6:37 am
  • added an answer Convert both strings to timestamps (in your chosen resolution, e.g.… May 11, 2026 at 6:37 am

Top Members

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

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.