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:stylesheet 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 3 9874
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:stylesheet 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:namespace-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:namespace-alias stylesheet-prefix="ns1" result-prefix="#default"/>
So putting those together, your stylesheet might look like...
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns1="abc"
xmlns="abc">
<xsl:namespace-alias stylesheet-prefix="ns1" result-prefix="#default"/>
<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:stylesheet 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**@progress-partnership.co.uk> wrote in message
news:72*************************@posting.google.co m... 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:stylesheet 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
<?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
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****@somewhere.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:stylesheet 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:namespace-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:namespace-alias stylesheet-prefix="ns1" result-prefix="#default"/>
So putting those together, your stylesheet might look like...
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns1="abc" xmlns="abc">
<xsl:namespace-alias stylesheet-prefix="ns1" result-prefix="#default"/>
<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:stylesheet 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**@progress-partnership.co.uk> wrote in message news:72*************************@posting.google.co m... 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:stylesheet 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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>";
...
|
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...
|
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?
...
|
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...
|
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...
|
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>
|
by: manchin2 |
last post by:
Hi,
Can anybody please provide the information about """ and its use, if possible please provide an example.
...
|
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...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: ezappsrUS |
last post by:
Hi,
I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
|
by: DizelArs |
last post by:
Hi all)
Faced with a problem, element.click() event doesn't work in Safari browser.
Tried various tricks like emulating touch event through a function:
let clickEvent = new Event('click', {...
|
by: F22F35 |
last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...
| |