473,387 Members | 1,303 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

can't get rid of xmlns attribute

Dormilich
8,658 Expert Mod 8TB
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 5417
jkmyoung
2,057 Expert 2GB
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 Expert Mod 8TB
@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 Expert Mod 8TB
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 Expert Mod 8TB
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 Expert 2GB
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 Expert Mod 8TB
@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
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"...
0
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"?>...
6
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...
4
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#...
0
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...
1
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...
3
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...
3
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...
13
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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...
0
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...

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.