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): - <xsl:stylesheet version="1.0"
-
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-
xmlns:plan="urn:kbl.plan:current-and-bygone-playlists" // default NS of the XML file
-
exclude-result-prefixes="xsl plan">
-
-
[...]
-
-
<xsl:template match="/">
-
<xsl:element name="div"> // either I have xmlns="..." here ...
-
<xsl:attribute name="class">
-
<xsl:text>mitte inhalt</xsl:text>
-
</xsl:attribute>
-
[...]
-
<xsl:for-each select="$basis/child::plan:thema">
-
<xsl:call-template name="themen" />
-
</xsl:for-each>
-
</xsl:element>
-
</xsl:template>
-
-
<xsl:template name="themen">
-
<xsl:call-template name="balken" />
-
<xsl:for-each select="plan:termin">
-
<xsl:call-template name="termine" />
-
</xsl:for-each>
-
<xsl:if test="plan:xhtml">
-
<xsl:copy-of select="plan:xhtml/*" /> // ... or here
-
</xsl:if>
-
</xsl:template>
-
6 5452 jkmyoung 2,057
Recognized Expert Top Contributor
Have you tried using a seperate copy template? -
<xsl:template name="copy">
-
<xsl:element name="local-name()">
-
<xsl:copy-of select="@*"/>
-
<xsl:for-each select="*">
-
<xsl:call-template name="copy"/>
-
</xsl:for-each>
-
</xsl:element>
-
</xsl:template>
-
-
Change
-
<xsl:copy-of select="plan:xhtml/*" />
-
with
-
<xsl:for-each select="plan:xhtml/*">
-
<xsl:call-template name="copy"/>
-
</xsl:for-each>
-
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
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: - <xsl:template name="copy">
-
// if I use this line I get the error
-
<xsl:element name="local-name()">
-
<xsl:copy-of select="@*"/>
-
<xsl:for-each select="*">
-
<xsl:call-template name="copy"/>
-
</xsl:for-each>
-
</xsl:element>
-
</xsl:template>
I have no idea, why it does so.....
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! - <xsl:template name="copy">
-
<xsl:element name="{local-name()}">
-
<xsl:copy-of select="@*"/>
-
<xsl:value-of select="text()"/>
-
<xsl:for-each select="plan:*">
-
<xsl:call-template name="copy"/>
-
</xsl:for-each>
-
</xsl:element>
-
</xsl:template>
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.
Dormilich 8,658
Recognized Expert Moderator Expert @jkmyoung
it was rather a lucky guess....
Sign in to post your reply or Sign up for a free account.
Similar topics |
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"?>
|
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"
|
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:
|
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
|
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
| |
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
|
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...
|
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...
|
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>
|
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...
|
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,...
| |
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...
|
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...
|
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,...
|
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...
|
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...
|
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();...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |