473,748 Members | 10,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

can't get rid of xmlns attribute

Dormilich
8,658 Recognized Expert Moderator Expert
Hi,

I have some problems removing the xmlns attributes from a transformed xml file. I can't completely remove them (so it would validate).

the problematic elements are <div> or the elements pasted by <xsl:copy-of>

if I have no default NS in the XSL file I get the namespace attribute attached to the copied elements (the one from the "plan" prefix because that's default NS of the XML, all prefixed NS are removed).

if I have a default NS in the XSL file, the copied elements are free of NS, but the NS is now attached to the <div> element (because it's the top level element in the result XML).

so, how do I need to change my copy construct to get all elements without NS?

alternatively I have to add a preg_replace() function to my script, if this is not possible with XSL......

the xsl file (the important part):
Expand|Select|Wrap|Line Numbers
  1. <xsl:stylesheet version="1.0"
  2.     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3.     xmlns:plan="urn:kbl.plan:current-and-bygone-playlists" // default NS of the XML file
  4.     exclude-result-prefixes="xsl plan">
  5.  
  6. [...]
  7.  
  8. <xsl:template match="/">
  9.   <xsl:element name="div">  // either I have xmlns="..." here ...
  10.     <xsl:attribute name="class">
  11.       <xsl:text>mitte inhalt</xsl:text>
  12.     </xsl:attribute>
  13. [...]
  14.     <xsl:for-each select="$basis/child::plan:thema">
  15.       <xsl:call-template name="themen" />
  16.     </xsl:for-each>
  17.   </xsl:element>
  18. </xsl:template>
  19.  
  20. <xsl:template name="themen">
  21.   <xsl:call-template name="balken" />
  22.   <xsl:for-each select="plan:termin">
  23.     <xsl:call-template name="termine" />
  24.   </xsl:for-each>
  25.   <xsl:if test="plan:xhtml">
  26.     <xsl:copy-of select="plan:xhtml/*" /> // ... or here
  27.   </xsl:if>
  28. </xsl:template>
  29.  
Dec 27 '08 #1
6 5452
jkmyoung
2,057 Recognized Expert Top Contributor
Have you tried using a seperate copy template?
Expand|Select|Wrap|Line Numbers
  1. <xsl:template name="copy">
  2.   <xsl:element name="local-name()">
  3.     <xsl:copy-of select="@*"/>
  4.     <xsl:for-each select="*">
  5.       <xsl:call-template name="copy"/>
  6.     </xsl:for-each>
  7.   </xsl:element>
  8. </xsl:template>
  9.  
  10. Change 
  11. <xsl:copy-of select="plan:xhtml/*" />
  12. with
  13. <xsl:for-each select="plan:xhtml/*">
  14.   <xsl:call-template name="copy"/>
  15. </xsl:for-each>
  16.  
Jan 5 '09 #2
Dormilich
8,658 Recognized Expert Moderator Expert
@jkmyoung
admittedly you are much better with such copy problems than I am. I'll try it.

regards
Jan 5 '09 #3
Dormilich
8,658 Recognized Expert Moderator Expert
tried the template but I got a problem. the XSLT returns with an error (i.e. the XSLTProcessor:: transformToXml( ) method returns false. I could narrow down the problem to the following:
Expand|Select|Wrap|Line Numbers
  1. <xsl:template name="copy">
  2. // if I use this line I get the error
  3.   <xsl:element name="local-name()">
  4.     <xsl:copy-of select="@*"/>
  5.     <xsl:for-each select="*">
  6.       <xsl:call-template name="copy"/>
  7.     </xsl:for-each>
  8.   </xsl:element>
  9. </xsl:template>
I have no idea, why it does so.....
Jan 8 '09 #4
Dormilich
8,658 Recognized Expert Moderator Expert
finally solved the problem, looked like the name attribute doesn't accept every input. nevertheless, thank you jkmyoung!
Expand|Select|Wrap|Line Numbers
  1. <xsl:template name="copy">
  2.   <xsl:element name="{local-name()}">
  3.     <xsl:copy-of select="@*"/>
  4.     <xsl:value-of select="text()"/>
  5.     <xsl:for-each select="plan:*">
  6.       <xsl:call-template name="copy"/>
  7.     </xsl:for-each>
  8.   </xsl:element>
  9. </xsl:template>
Jan 8 '09 #5
jkmyoung
2,057 Recognized Expert Top Contributor
Sorry, forgot that attribute was a string, not an xpath. But you figured out the braces so it's ok.
Jan 8 '09 #6
Dormilich
8,658 Recognized Expert Moderator Expert
@jkmyoung
it was rather a lucky guess....
Jan 8 '09 #7

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

Similar topics

7
1670
by: Julio | last post by:
Hi, I have problem with namespaces and attributes. I want to get this: <grammar xmlns="http://www.w3.org/2001/06/grammar" xmlns:sapi="http://schemas.microsoft.com/Speech/2002/06/SRGSExtensions" > I have the following XSLT: <?xml version="1.0" encoding="UTF-8"?>
0
1900
by: chris.stromberger | last post by:
New to SOAP. I am working on something that uses the paypal web services. All the examples have this as the first portion of the soap doc <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
6
2589
by: Martin | last post by:
Hi, I have a xml file like the one below <?xml version="1.0" encoding="utf-8"?><e1 xmlns:e1="http://tempuri.org/Source1.xsd" e1:att1="1" e1:att2="2" e1:rest="345"/> If I try to create a schema for it with Visual Studio, I get the error "Failed to create a schema for this data file because:
4
3594
by: David S. Alexander | last post by:
I am trying to transform XML to XML using an XSLT in C#, but the root node of my XML is not being matched by the XSLT if it has an xmlns attribute. Am I handling my namespaces incorrectly? My C# code is, // Create an XSLT transform object XslTransform xslTransform = new XslTransform(); // Load the stylesheet
0
2024
by: Ewan Fairweather | last post by:
Hi, I'm generating the below XML in c# for an asp.net application When i've generated this XML the <LaboratoryDetails xmlns=""> element has a blank xmlns set. How do i either a) remove this attribute or b) prevent it from happening in the first place. To generate the xml I've got two template files which i've included at the bottom of this post. Two xmldocuments are created in my code which load the
1
2996
by: Ewan Fairweather | last post by:
Hi, I'm generating the below XML in c# for an asp.net application When i've generated this XML the <LaboratoryDetails xmlns=""> element has a blank xmlns set. How do i either a) remove this attribute or b) prevent it from happening in the first place. To generate the xml I've got two template files which i've included at the bottom of this post. Two xmldocuments are created in my code which load the
3
4029
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user selects? thanks...
3
3904
by: =?Utf-8?B?R3JlZw==?= | last post by:
If I have an XmlDocument with a deep hierarchy of nodes, with a documentElement having an attribute xmlns="http://someurl.com" and all children inheriting that namespace (but not having the xmlns attribute explicitly declared), then why is it that when I perform appendChild(someNode) on an existing node deep in the hierarchy, where someNode has been created by an XmlSerializer with the namespace set to be the aforementioned...
13
8159
by: Bill Nguyen | last post by:
Is it possible to create your won XSD to use with .NET based on an XML content? For example the one below: <?xml version="1.0"?> <pcats:FuelsDoc xmlns="http://www.naxml.org/Retail-EDI/Vocabulary/2003-10-16" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="NAXML-FuelPrice15.xsd"> <pcats:TransmissionHeader>
0
8989
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
8828
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
9537
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
9367
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
9319
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
9243
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8241
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...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.