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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:11:48+00:00 2026-05-23T23:11:48+00:00

I have a huge xml file that I would like to split up into

  • 0

I have a huge xml file that I would like to split up into individual xml documents; each individual xml file is supposed to have an explicit namespace declaration where applicable as show in the “Desired Output” portion below. However, I keep getting the error “namespace error : Namespace prefix bd on keyword is not defined”

My question is, how can I explicitly tell my XSLT processor where to put namespace declaration in resulting output? I have gone through a couple of tutorials online, but I can’t quite figure out how to sort this out.

Partial XSLT Snippet

...
...
<xsl:template match="chapter">
  <bd:chapter>
    <xsl:apply-templates select="name" />
    <xsl:apply-templates select="page" />
  </bd:chapter>
</xsl:template>

<xsl:template match="name">
  <bd:name>
    <xsl:value-of select="." />
  </bd:name>
</xsl:template>
...
...

Desired Output

<?xml version="1.0" encoding="utf-8" ?>
<books>
<bd:book xmlns:bd="http://www.bd.org.za/db" xmlns:cd="http://www.bd.org.za/cd">
    <bd:name>book01</bd:name>
    <bd:chapter>
      <cd:name>chapter01<cd:name>
      <bd:page>
    <cd:title></cd:title>
    <pd:description></pd:description>
      </bd:page>
    </bd:chapter>
</bd:book>
...
...
...
</books>

Update #1

<?xml version="1.0" encoding="utf-8" ?>
<books>
<book>
    <name>book01</name>
    <chapter>
      <name>chapter01<name>
      <page>
    <title></title>
    <description></description>
      </page>
    </chapter>
</book>
...
...
...
</books>

Update #2

@polishchuk Update2 give the following result

<?xml version="1.0"?>
<root xmlns:pd="namespace2">
  <pd:Book xmlns:pd="http://namespace1.org/">
    <pd_1:Name xmlns:pd="namespace2" xmlns:pd_1="http://namespace1.org/">A</pd_1:Name>
    <pd:Description xmlns:pd="namespace2">A1</pd:Description>
  </pd:Book>
  <pd:Book xmlns:pd="http://namespace1.org/">
    <pd_1:Name xmlns:pd="namespace2" xmlns:pd_1="http://namespace1.org/">B</pd_1:Name>
    <pd:Description xmlns:pd="namespace2">B1</pd:Description>
  </pd:Book>
</root>

The only pace I would like the namespaces to appear is within the book node. Please see below

<?xml version="1.0"?>
<root>
  <pd:Book xmlns:pd="http://namespace1.org/">
    <pd:Name >A</pd:Name>
    <pd:Description>A1</pd:Description>
  </pd:Book>
  <pd:Book xmlns:pd="http://namespace1.org/">
    <pd:Name>B</pd_1:Name>
    <pd:Description>B1</pd:Description>
  </pd:Book>
</root>
  • 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-23T23:11:49+00:00Added an answer on May 23, 2026 at 11:11 pm

    Suppose you have following XML:

    <root>
      <book>
        <name>A</name>
        <description>A1</description>
      </book>
      <book>
        <name>B</name>
        <description>B1</description>
      </book>
    </root>
    

    Desired XML (with namespaces):

    <root xmlns:bd="namespace1" xmlns:pd="namespace2">
      <bd:Book>
        <bd:Name>A</bd:Name>
        <pd:Description>A1</pd:Description>
      </bd:Book>
      <bd:Book>
        <bd:Name>B</bd:Name>
        <pd:Description>B1</pd:Description>
      </bd:Book>
    </root>
    

    Appropriate XSLT:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    xmlns:bd="namespace1"
                    xmlns:pd="namespace2"
                    >
      <xsl:output method="xml" indent="yes"/>
    
      <xsl:template match="/">
        <root>
          <xsl:apply-templates/>
        </root>
      </xsl:template>
    
      <xsl:template match="book">
        <bd:Book>
          <xsl:apply-templates />
        </bd:Book>
      </xsl:template>
    
      <xsl:template match="name">
        <bd:Name>
          <xsl:value-of select="."/>
        </bd:Name>
      </xsl:template>
    
      <xsl:template match="description">
        <pd:Description>
          <xsl:value-of select="."/>
        </pd:Description>
      </xsl:template>
    
    </xsl:stylesheet>
    

    You simply add namespaces in XSLT, then create nodes using namespace’s prefix.

    Update 1:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    xmlns:pd="namespace2"
                    >
      <xsl:output method="xml" indent="yes"/>
    
      <xsl:template match="/">
        <root>
          <xsl:apply-templates/>
        </root>
      </xsl:template>
    
      <xsl:template match="book">
        <bd:Book xmlns:bd="namespace1">
          <xsl:apply-templates />
        </bd:Book>
      </xsl:template>
    
      <xsl:template match="name">
        <bd:Name xmlns:bd="namespace1">
          <xsl:value-of select="."/>
        </bd:Name>
      </xsl:template>
    
      <xsl:template match="description">
        <pd:Description>
          <xsl:value-of select="."/>
        </pd:Description>
      </xsl:template>
    
    </xsl:stylesheet>
    

    Update 2:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    xmlns:pd="namespace2"
                    >
      <xsl:output method="xml" indent="yes"/>
    
      <xsl:template match="/">
        <root>
          <xsl:apply-templates/>
        </root>
      </xsl:template>
    
      <xsl:template match="book">
        <Book xmlns="namespace1">
          <xsl:apply-templates />
        </Book>
      </xsl:template>
    
      <xsl:template match="name">
        <Name xmlns="namespace1">
          <xsl:value-of select="."/>
        </Name>
      </xsl:template>
    
      <xsl:template match="description">
        <pd:Description>
          <xsl:value-of select="."/>
        </pd:Description>
      </xsl:template>
    
    </xsl:stylesheet>
    

    Update 3:
    This XSLT:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="xml" indent="yes"/>
    
      <xsl:template match="/">
        <root>
          <xsl:apply-templates/>
        </root>
      </xsl:template>
    
      <xsl:template match="book">
        <pd:Book xmlns:pd="namespace2">
          <xsl:apply-templates />
        </pd:Book>
      </xsl:template>
    
      <xsl:template match="name">
        <pd:Name  xmlns:pd="namespace2">
          <xsl:value-of select="."/>
        </pd:Name>
      </xsl:template>
    
      <xsl:template match="description">
        <pd:Description  xmlns:pd="namespace2">
          <xsl:value-of select="."/>
        </pd:Description>
      </xsl:template>
    
    </xsl:stylesheet>
    

    Output XML (like in your Update 2, I use MSXML 6.0), but for XML engine no matter where namespace is defined:

    <root>
      <pd:Book xmlns:pd="namespace2">
        <pd:Name>A</pd:Name>
        <pd:Description>A1</pd:Description>
      </pd:Book>
      <pd:Book xmlns:pd="namespace2">
        <pd:Name>B</pd:Name>
        <pd:Description>B1</pd:Description>
      </pd:Book>
    </root>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple but huge xml file like below. I want to parse
I have a huge SVG file inside a DIV. I would like to scroll
I have a huge file that I must parse line by line. Speed is
I have this very huge XML file of size 2.8GB. This is Polish Wikipedia's
This is one of the entries I have in a huge XML file of
I have to read a huge xml file which consists of over 3 million
I have to resolve a problem close to parsing a huge file like, 3
I have a huge XML file I need to do a Search and Replace
I have a huge xml file and i want to convert it to a
I have a huge bunch of XML files with the following structure: <Stuff1> <Content>someContent</name>

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.