473,847 Members | 1,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

default namespace and xmlns=""

hi,
i'm sure this has come up before but havn't managed to find an answer.
if i have the following xslt

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:styleshe et method="xml" version="1.0" xmlns:ns1="abc"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" media-type="text/xml" standalone="yes "
version="1.0"/>
<xsl:template match="/">
<x>
<xsl:element name="y" namespace="abc" >
<xsl:apply-templates select="/a"/>
</xsl:element>
</x>
</xsl:template>
<xsl:template match="/a">
<z>
<xsl:value-of select="b"/>
</z>
</xsl:template>
</xsl:stylesheet>

and apply it to the following xml

<a>
<b>hello</b>
</a>

i get

<?xml version="1.0" standalone="yes "?>
<x xmlns:ns1="abc" >
<y xmlns="abc">
<z xmlns="">hello</z>
</y>
</x>

my question is this. is it possible to remove the xmlns="" bit without
having to use <ns1:z> in the xslt?

thanks,
mike
Jul 20 '05 #1
3 10045
Hi Mike,
my question is this. is it possible to remove the xmlns="" bit without
having to use <ns1:z> in the xslt?
It is not possible to 'remove' namespace declarations placed in the output
by the transformation engine. The transformation engine decides, to some
degree under your instruction, what namespace declarations are needed.
In this case your <z> element is bound to the null namespace (i.e. the
namespace URI is "") - the only way to 'removing' that namespace declaration
would be to bind the <z> element to a different namespace... which I
suspect, but am not sure, is what you are asking... how to bind <z> to the
"abc" namespace?

One way to start taking control of your output namespace is to define the
default output namespace in your stylesheet, e.g.

<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:ns1="abc"
xmlns="abc">

The default namespace for the stylesheet is used as the default namespace
for the output.

Having done that, then you only need to specify namespace prefixes (or
@namespace-uri on <xsl:element>/<xsl:attribute> ) where you want
elements/attributes to be bound to a different namespace to the default
output namespace.

Another thing that can help you 'control' (to a degree) the output namespace
declarations is to use the <xsl:namespac e-alias> instruction, for example to
declare your prefix 'ns1' (e.g. xmlns:ns1="abc" ) in the stylesheet and then
have that transposed to the default output namespace (e.g. xmlns="abc")
would be to specify that...

<xsl:namespac e-alias stylesheet-prefix="ns1" result-prefix="#defaul t"/>

So putting those together, your stylesheet might look like...

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:ns1="abc"
xmlns="abc">

<xsl:namespac e-alias stylesheet-prefix="ns1" result-prefix="#defaul t"/>

<xsl:output indent="yes" media-type="text/xml" standalone="yes "
version="1.0"/>
<xsl:template match="/">
<x>
<ns1:y>
<xsl:apply-templates select="/a"/>
</ns1:y>
</x>
</xsl:template>

<xsl:template match="/a">
<z>
<xsl:value-of select="b"/>
</z>
</xsl:template>
</xsl:stylesheet>

which would give an output of...

<?xml version="1.0" encoding="UTF-16" standalone="yes "?>
<x xmlns="abc">
<y>
<z>hello</z>
</y>
</x>

Although then there would be no particular reason to declare the 'ns1'
namespace prefix at all nor specify the @namespace-uri attribute on
<xsl:element> (come to that, there is no particular reason to use
<xsl:element> in this case at all). So your stylesheet really just needs to
be...

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns="abc">

<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<x>
<y>
<xsl:apply-templates select="/a"/>
</y>
</x>
</xsl:template>

<xsl:template match="/a">
<z>
<xsl:value-of select="b"/>
</z>
</xsl:template>
</xsl:stylesheet>

NB. Really, the only times when you need to use <xsl:element> is where the
element name or namespace URI is being defined dynamically, i.e. where
either the @name or @namespace-uri attributes contain an AVT (attribute
value template).

HTH
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator

"Mike Dickens" <mi**@progres s-partnership.co. uk> wrote in message
news:72******** *************** **@posting.goog le.com... hi,
i'm sure this has come up before but havn't managed to find an answer.
if i have the following xslt

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:styleshe et method="xml" version="1.0" xmlns:ns1="abc"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" media-type="text/xml" standalone="yes "
version="1.0"/>
<xsl:template match="/">
<x>
<xsl:element name="y" namespace="abc" >
<xsl:apply-templates select="/a"/>
</xsl:element>
</x>
</xsl:template>
<xsl:template match="/a">
<z>
<xsl:value-of select="b"/>
</z>
</xsl:template>
</xsl:stylesheet>

and apply it to the following xml

<a>
<b>hello</b>
</a>

i get

<?xml version="1.0" standalone="yes "?>
<x xmlns:ns1="abc" >
<y xmlns="abc">
<z xmlns="">hello</z>
</y>
</x>

my question is this. is it possible to remove the xmlns="" bit without
having to use <ns1:z> in the xslt?

thanks,
mike

Jul 20 '05 #2


<?xml version="1.0" standalone="yes "?>
<x xmlns:ns1="abc" >
<y xmlns="abc">
<z xmlns="">hello</z>
</y>
</x>

my question is this. is it possible to remove the xmlns="" bit without
having to use <ns1:z> in the xslt?
You probbaly want to generate z in the namespace abc which you could do
in the xsl by using
<z xmlns="abc">

Usuallly you put such a result namespace declaration on your
xsl:stylesheet element then it's in scope for the whole stylesheet and
would mean you could replace
<xsl:element name="y" namespace="abc" >
by
<y>

and just use <z> to generate z.

If you really want x to be in no-namespace you could do
<xsl:element name="x" namespace="">

David
Jul 20 '05 #3
yes, that's what i meant, though possible put as have <z> inherit the
namespace of it's parent rather bind to "abc" specifically. this is
because there are potentially lots of z's...

"Marrow" <ma****@somewhe re.so.fu> wrote in message news:<8S******* ******@newsfe2-gui.ntli.net>.. .
Hi Mike,
my question is this. is it possible to remove the xmlns="" bit without
having to use <ns1:z> in the xslt?


It is not possible to 'remove' namespace declarations placed in the output
by the transformation engine. The transformation engine decides, to some
degree under your instruction, what namespace declarations are needed.
In this case your <z> element is bound to the null namespace (i.e. the
namespace URI is "") - the only way to 'removing' that namespace declaration
would be to bind the <z> element to a different namespace... which I
suspect, but am not sure, is what you are asking... how to bind <z> to the
"abc" namespace?

One way to start taking control of your output namespace is to define the
default output namespace in your stylesheet, e.g.

<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:ns1="abc"
xmlns="abc">

The default namespace for the stylesheet is used as the default namespace
for the output.

Having done that, then you only need to specify namespace prefixes (or
@namespace-uri on <xsl:element>/<xsl:attribute> ) where you want
elements/attributes to be bound to a different namespace to the default
output namespace.

Another thing that can help you 'control' (to a degree) the output namespace
declarations is to use the <xsl:namespac e-alias> instruction, for example to
declare your prefix 'ns1' (e.g. xmlns:ns1="abc" ) in the stylesheet and then
have that transposed to the default output namespace (e.g. xmlns="abc")
would be to specify that...

<xsl:namespac e-alias stylesheet-prefix="ns1" result-prefix="#defaul t"/>

So putting those together, your stylesheet might look like...

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:ns1="abc"
xmlns="abc">

<xsl:namespac e-alias stylesheet-prefix="ns1" result-prefix="#defaul t"/>

<xsl:output indent="yes" media-type="text/xml" standalone="yes "
version="1.0"/>
<xsl:template match="/">
<x>
<ns1:y>
<xsl:apply-templates select="/a"/>
</ns1:y>
</x>
</xsl:template>

<xsl:template match="/a">
<z>
<xsl:value-of select="b"/>
</z>
</xsl:template>
</xsl:stylesheet>

which would give an output of...

<?xml version="1.0" encoding="UTF-16" standalone="yes "?>
<x xmlns="abc">
<y>
<z>hello</z>
</y>
</x>

Although then there would be no particular reason to declare the 'ns1'
namespace prefix at all nor specify the @namespace-uri attribute on
<xsl:element> (come to that, there is no particular reason to use
<xsl:element> in this case at all). So your stylesheet really just needs to
be...

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns="abc">

<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<x>
<y>
<xsl:apply-templates select="/a"/>
</y>
</x>
</xsl:template>

<xsl:template match="/a">
<z>
<xsl:value-of select="b"/>
</z>
</xsl:template>
</xsl:stylesheet>

NB. Really, the only times when you need to use <xsl:element> is where the
element name or namespace URI is being defined dynamically, i.e. where
either the @name or @namespace-uri attributes contain an AVT (attribute
value template).

HTH
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator

"Mike Dickens" <mi**@progres s-partnership.co. uk> wrote in message
news:72******** *************** **@posting.goog le.com...
hi,
i'm sure this has come up before but havn't managed to find an answer.
if i have the following xslt

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:styleshe et method="xml" version="1.0" xmlns:ns1="abc"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" media-type="text/xml" standalone="yes "
version="1.0"/>
<xsl:template match="/">
<x>
<xsl:element name="y" namespace="abc" >
<xsl:apply-templates select="/a"/>
</xsl:element>
</x>
</xsl:template>
<xsl:template match="/a">
<z>
<xsl:value-of select="b"/>
</z>
</xsl:template>
</xsl:stylesheet>

and apply it to the following xml

<a>
<b>hello</b>
</a>

i get

<?xml version="1.0" standalone="yes "?>
<x xmlns:ns1="abc" >
<y xmlns="abc">
<z xmlns="">hello</z>
</y>
</x>

my question is this. is it possible to remove the xmlns="" bit without
having to use <ns1:z> in the xslt?

thanks,
mike

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1315
by: johnsocs | last post by:
All I'm trying to write an xml schema for the following xml from the google web service api. In the schema I'm not sure how to describe the soapenv:encodingStyle attribute. Thanks. <?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
1
2092
by: Zhenya Sigal via .NET 247 | last post by:
I have the following code: XmlElement parent= m_xmlDoc.CreateElement("parent", "http://tempuri.org/myns"); parent.InnerXml = "<child1>text</child1><child2>text</child2>"; "http://tempuri.org/myns" is declared as the default namespace for this xml file. When I set InnerXml above, each <child> node gets the following extra attribute: xmlns="". I'd like child nodes to inherit the default namespace instead of the empty namespace. How can I...
3
7145
by: Keith Hill | last post by:
I am creating an XmlDocument in code and then using XmlTextWriter via doc.WriteTo(xwriter) to output the result to a text box. I have a root element that defines a default namespace. However, the sub-elements are created without any namespaces like so: XmlElement elem = doc.CreateElement("Foo"); root.AppendChild(elem); but in the output I get this:
6
13602
by: TS | last post by:
Hi, i have a problem validating xml against schema. I used http://apps.gotdotnet.com/xmltools/xsdvalidator/Default.aspx validator and it says it is fine. Can you tell me why this doesn't work? Thanks! Schema: <?xml version="1.0"?> <xs:schema id="ReportInfo" targetNamespace="http://tempuri.org/Reports.xsd"
5
12447
by: NeilL | last post by:
In the XML document I'm trying to create I do the following elem = _doc.CreateElement("Author"); elem.InnerText = "something"; parentElem.AppendChild(elem); Thiw works properly however the resulting XML file has the following <Author xmlns="">something</Author>
0
1603
by: R. Ian Lee | last post by:
I've built an XSLT file that transforms data to SpreadsheetML format. The XSLT uses a <xsl:call-template/to build each worksheet. For some reason, when I transform the file, it is inserting xmlns="" attributes into my <Worksheetelements which causes the worksheet not to work with Excel. I'm using the System.Xml.Xsl.XslTransform class to perform the transform. Here's a snippet of the XSLT template that is called: <xsl:template...
3
5467
by: olympus_mons | last post by:
Hi all, my XML looks like: <root xmlns="tempuri.org"> <result xmlns=""> <date>2006-09-14</date> <status>ok</status> </result> </root>
1
2846
by: manchin2 | last post by:
Hi, Can anybody please provide the information about "&quot" and its use, if possible please provide an example. 1)<tm:bom-expression>{Conf.getEquityConfLookupFields().getEventFieldText(&quot;AdditionalDisruption&quot;,&quot;Change in Law&quot;)}</tm:bom-expression> 2)07:41:08 Default ( call ( . ( call ( . Conf getEquityConfLookupFields ) ) getEventFieldText ) ( , AdditionalDisruption Change inLaw ) ) value=Not applicable Can you please...
4
4824
by: BorisBoshond | last post by:
Hi all, Hope someone is able and willing to help me with following problem. I received a xsd file from another company, our company i supposed to return xml based on that xsd. Problem is that I don't really understand how these namespace work in xml. (I am however aware of what problems namespaces solve) I'm not even sure if the provided xsd is 'common' practice, although it validates correctly. So I'll describe exactly what I've...
0
9882
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10645
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10706
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9481
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7880
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5719
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5909
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4524
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3160
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.