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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:26:16+00:00 2026-06-13T11:26:16+00:00

I have an XSLT stylesheet that needs to emit an XML fragment that looks

  • 0

I have an XSLT stylesheet that needs to emit an XML fragment that looks like this (the “…” bits are elided for brevity) :

<MyOuterType xmlns:xsi="..." xsi:type="foo:MyInnerType" xmlns:foo="..."/>

The stylesheet looks like this :

<xsl:stylesheet xmlns:foo="..." xmlns:xsi="...">
  ...
  <xsl:template match="...">
    <xsl:element name="MyOuterType">
      <xsl:attribute name="xsi:type">foo:MyInnerType</xsl:attribute>
    </xsl:element>
  </xsl:template>
</xsl:stylesheet>

The XSLT processor’s output looks like this :

<MyOuterType xmlns:xsi="..." xsi:type="foo:MyInnerType"/>

In other words, it’s missing the xmlns:foo declaration. In fact the declaration is completely absent from the emitted XML, despite it being declared in the stylesheet. This messes things up later, when I need to deserialize the emitted XML.

How can I get my xmlns:foo to appear in the emitted XML? The processor implements XSLT 1.0.

  • 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-13T11:26:17+00:00Added an answer on June 13, 2026 at 11:26 am

    It depends whether you know the namespace you want to generate statically, or whether it’s based on information in the input document.

    If you know it statically, just use a literal result element instead of xsl:element:

    <MyOuterType xsi:type="foo:MyInnerType" xmlns:foo="....."/>
    

    If it’s a dynamic decision, it’s a bit more complicated. XSLT 2.0 has an xsl:namespace instruction to generate namespaces in much the same way that xsl:attribute generates attributes. In XSLT 1.0, the trick is to create an element that contains the required namespace, and then use xsl:copy to copy the namespace node:

    <xsl:variable name="dummy">
      <xsl:element name="foo:dummy" namespace="{$param}"/>
    </xsl:variable>
    <MyOuterType xsi:type="foo:MyInnerType">
      <xsl:copy-of select="exsl:node-set($dummy)/*/namespace::foo"/>
    </MyOuterType>
    

    Unfortunately there are one or two not-quite-XSLT-1.0 processors out there that don’t implement namespace nodes correctly, so exercise caution.

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

Sidebar

Related Questions

I have got an XSLT that looks like this: <xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform> <xsl:output method=xml
I have an xml file that looks like this: <args> <sometag value=abc /> <anothertag
I have an XSLT stylesheet that transforms an XML file to JSON format and
Lets say I have a xslt stylesheet like the following: <?xml version=1.0 encoding=utf-8?> <xsl:stylesheet
I have an xslt stylesheet that needs to call a C# XSLT extension function
I have an XSLT stylesheet that processes an XML document to produce HTML. I've
I have a xml that looks like below one. I need your help to
I currently have a XSLT 2.0 Stylesheet that I am trying to remove empty
I have this XSLT 2.0: <xsl:stylesheet version=2.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform> <xsl:output indent=yes/> <xsl:strip-space elements=*/> <xsl:template match=node()|@*>
I have an XML EDITED: <?xml version=1.0 encoding=UTF-8?> <?xml-stylesheet type=text/xsl href=xsl.xslt?> <CATALOG> <CD> </CD>

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.