473,791 Members | 3,097 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

remove blank (xmlns="") from elements

markmcgookin
648 Recognized Expert Contributor
Hi,

I am creating an MXL doc using XSLT but for some reason it is churning out elements like this

Expand|Select|Wrap|Line Numbers
  1. <DateTimeLastSaved xmlns="" />
  2. <UserName xmlns="" />
when I delete xmlns="" it works fine, but if I leave it in there are issues reading/saving the file. Is there any way to remove this xmlns="" in the xslt?

Cheers,

Mark
Dec 10 '07 #1
4 17895
jkmyoung
2,057 Recognized Expert Top Contributor
When you are creating the elements, you need to have the same namespace as the parent elements (xmlns = XMLNameSpace) . Add the parent's namespace to those elements when you are creating it.

eg probably something like

xmlns="www.yaho o.com"
Dec 10 '07 #2
markmcgookin
648 Recognized Expert Contributor
Hi there,

I noticed that people were able to solve this problem here, I just hope that re-using this thread will get me a responce here.... I have the same problem, where my xslt is producing elements but all with xmlns="" in them, and when I remove it manually my code works fine, but just using the raw output my code falls over... would anyone be able to help me?

Thanks very much for any help folks,

Really appreciated.

Mark (Code Below)

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?xml version="1.0" encoding="UTF-8" ?>
  3. <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  4.     <xsl:param name="fileName"></xsl:param>
  5.     <xsl:param name="schemaName"></xsl:param>
  6.     <xsl:output method="xml" indent="yes" omit-xml-declaration="no" />
  7.  
  8.     <!-- Template that read the root node -->
  9.     <xsl:template match="/">
  10.  
  11.         <xsl:variable name="myNS">
  12.             <xsl:text>http://tempuri.org/</xsl:text>
  13.             <xsl:value-of select="$schemaName"/>
  14.             <xsl:text>.xsd</xsl:text>
  15.         </xsl:variable>
  16.  
  17.         <xsl:element name="AnswerList" namespace="{$myNS}">
  18.             <!-- NB: Done like this because the template match doesnt work -->
  19.             <!-- May be an issue with the xml that was generated from the QTi -->
  20.             <xsl:element name="DateTimeLastSaved" />
  21.             <xsl:element name="UserName"/>
  22.  
  23.  
  24.             <xsl:for-each select="child::node()">
  25.  
  26.                 <xsl:for-each select="child::node()">
  27.                     <xsl:apply-templates select="DSDetailView/DetailView" />
  28.                     <xsl:for-each select="child::node()">
  29.                         <xsl:apply-templates select="DSDetailView/DetailView" />
  30.                         <xsl:choose>
  31.                             <!-- If it's called Item -->
  32.                             <xsl:when test="name()='Item'">
  33.                                 <xsl:choose>
  34.                                     <!-- If it's a textbox -->
  35.                                     <xsl:when test="@Type='Resco.Controls.DetailView.ItemTextBox'">
  36.                                         <xsl:for-each select="child::node()">
  37.                                             <xsl:choose>
  38.                                                 <!-- If it stored Data i.e. not a lable -->
  39.                                                 <xsl:when test="@Name='DataMember'">
  40.  
  41.                                                     <xsl:variable name="temp">
  42.                                                         <xsl:value-of select="@Value"/>
  43.                                                     </xsl:variable>
  44.  
  45.                                                     <!-- Create a string object in the schema -->
  46.                                                     <xsl:element name="{$temp}">
  47.                                                     </xsl:element>
  48.                                                     <!-- End of create a string object in the schema -->
  49.  
  50.                                                 </xsl:when>
  51.                                             </xsl:choose>
  52.                                         </xsl:for-each>
  53.                                     </xsl:when>
  54.  
  55.                                     <!-- If it's a radio button thing -->
  56.                                     <xsl:when test="@Type='ALPS_Demo.ItemRadioButton, ALPS_Demo'">
  57.                                         <!-- Create an int object in the schema -->
  58.                                         <xsl:for-each select="child::node()">
  59.                                             <xsl:choose>
  60.                                                 <!-- If it stored Data i.e. not a lable -->
  61.                                                 <xsl:when test="@Name='DataMember'">
  62.  
  63.                                                     <xsl:variable name="temp">
  64.                                                         <xsl:value-of select="@Value"/>
  65.                                                     </xsl:variable>
  66.  
  67.                                                     <!-- Create an Int object in the schema -->
  68.                                                     <xsl:element name="{$temp}">
  69.                                                         <xsl:text>-1</xsl:text>
  70.                                                     </xsl:element>
  71.                                                     <!-- Create an Int object in the schema -->
  72.  
  73.                                                 </xsl:when>
  74.                                             </xsl:choose>
  75.                                         </xsl:for-each>
  76.                                     </xsl:when>
  77.                                 </xsl:choose>
  78.                             </xsl:when>
  79.                         </xsl:choose>
  80.                     </xsl:for-each>
  81.                 </xsl:for-each>
  82.             </xsl:for-each>
  83.  
  84.         <!-- Generic Answerlist footer code -->
  85.         </xsl:element>
  86.         <!-- Generic Answerlist footer code -->
  87.  
  88.  
  89.         </xsl:template>
  90. </xsl:stylesheet>
  91.  
  92.  
  93.  
Which I need to produce

Expand|Select|Wrap|Line Numbers
  1. <AnswerList xmlns="http://tempuri.org/ALPS_Assessmentv1p1_RESCO_Schema.xsd">
  2.     <DateTimeLastSaved />
  3.     <UserName />
  4.     <Ans_1189068258258 />
  5.     <Ans_1188555751625_MC0>-1</Ans_1188555751625_MC0>
  6.     <Ans_1188555751625_MC1>-1</Ans_1188555751625_MC1>
  7.     <Ans_1188555751625_MC2>-1</Ans_1188555751625_MC2>
  8.     <Ans_1188555751625_MC3>-1</Ans_1188555751625_MC3>
  9. </AnswerList>
  10.  
But is producing

Expand|Select|Wrap|Line Numbers
  1. <AnswerList xmlns="http://tempuri.org/ALPS_Assessmentv1p1_RESCO_Schema.xsd">
  2.     <DateTimeLastSaved xmlns="" />
  3.     <UserName xmlns="" />
  4.     <Ans_1189068258258 xmlns="" />
  5.     <Ans_1188555751625_MC0 xmlns="">-1</Ans_1188555751625_MC0>
  6.     <Ans_1188555751625_MC1 xmlns="">-1</Ans_1188555751625_MC1>
  7.     <Ans_1188555751625_MC2 xmlns="">-1</Ans_1188555751625_MC2>
  8.     <Ans_1188555751625_MC3 xmlns="">-1</Ans_1188555751625_MC3>
  9. </AnswerList>
  10.  
Dec 12 '07 #3
jkmyoung
2,057 Recognized Expert Top Contributor
Wherever you have an <xsl:element> tag, be sure to use the namespace attribute.
Expand|Select|Wrap|Line Numbers
  1. <xsl:element name="DateTimeLastSaved" namespace="{$myNS}"/>
  2. <xsl:element name="UserName" namespace="{$myNS}"/>
  3.  
Dec 12 '07 #4
awesome.. it worked..
Sep 29 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2091
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
7144
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:
5
12443
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>
3
3331
by: Jim Hsu | last post by:
when I use the XmlWebSerivce to response the xmlelement to Web Service client. the ASP.net plumbing work ( the XmlSerializer in WebServices ) will serialize the XML if we can control the wrapper class , I can set the XmlSchemaForm.None or Qualified so that there will no be a 'xmlns=""' in the following namespace, but I don't know how to do that in WebService plumbing. this null namespace will makes my web service wrapper class complains....
3
9911
by: ano | last post by:
Hi, Anyone knows how to get "xmlns" value from XML file? For example, how to check that this xml file has a xmlns or not? Or how to read the xmlns value? <bookstore xmlns:bk="http://www.lucernepublishing.com"> <book> <title>Pride And Prejudice</title> </book>
0
1598
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...
0
1438
by: SolaFide | last post by:
I have an XML doc that looks something like this: <?xml version="1.0" encoding="utf-8"?> <elem1> <elem2 xmlns="http://someurl.com"> <elem3> <item>some stuff here</item> <item>some more stuff here</item> <item>even more stuff here</item> </elem3>
2
9516
by: Lee | last post by:
Hello guys, I am new to XML and working on a XSLT to transforn yahoo shopping search result to html. my problem is the return XML contain xmlns in root element, here is the sample xml: <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="aproductsearch.xslt"?> <ProductSearch xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:yahoo:aprods" xsi:schemaLocation="urn:yahoo:aprods...
4
4821
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
9669
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
9515
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10427
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
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...
0
9029
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
7537
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
5431
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...
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2916
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.