473,769 Members | 4,052 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML an identical copy using XSLT

Hi,

i get stucked on a transformation problem using XSLT. What i need is
to copy an XML Tree to an output XML without any automatic changes.
Since i used <xsl:copyor <xsl:copy-ofthere occur unwanted side
effects.
For example i just copied a xml were several namespace declarations
are present more than one time. Then
the transformation do remove the declaration at the child nodes.
Another funny automatism is - if i remove a node
which holds a namespace declaration the first child is inheriting its
declaration.

Thank you for your support,

Im looking forward to hearing from yoou soon.

Wolfram
Jun 27 '08 #1
6 4340
kl***********@g ooglemail.com wrote:
i get stucked on a transformation problem using XSLT. What i need is
to copy an XML Tree to an output XML without any automatic changes.
Since i used <xsl:copyor <xsl:copy-ofthere occur unwanted side
effects.
For example i just copied a xml were several namespace declarations
are present more than one time. Then
the transformation do remove the declaration at the child nodes.
Another funny automatism is - if i remove a node
which holds a namespace declaration the first child is inheriting its
declaration.
If you have e.g.
<foo xmlns="http://example.com/2008/ns1">
<bar>
<baz/>
</bar>
</foo>
then all three elements are in the namespace
http://example.com/2008/ns1. Consequently if you copy the bar element
without its foo parent then the serializer has to add a xmlns
declaration to make sure the copied element is still in its namespace.

In the XSLT/XPath 1.0 data model there are namespace nodes which are in
scope for element nodes. And xsl:copy http://www.w3.org/TR/xslt#copying
copies these namespace nodes.
With XSLT 2.0 http://www.w3.org/TR/xslt20/#shallow-copy you can specify
whether namespaces are copied but for the namespace of the element
itself that would not prevent the copying of its namespace. If you want
to strip the namespace of an element then you can't use xsl:copy,
instead you need to create a new element e.g.

<xsl:template match="pf1:bar"
xmlns:pf1="http ://example.com/2008/ns1">

<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>

</xsl:template>
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 27 '08 #2
On 20 Mai, 13:09, Martin Honnen <mahotr...@yaho o.dewrote:
kluge.wolf...@g ooglemail.com wrote:
i get stucked on a transformation problem using XSLT. What i need is
to copy an XML Tree to an output XML without any automatic changes.
Since i used <xsl:copyor <xsl:copy-ofthere occur unwanted side
effects.
For example i just copied a xml were several namespace declarations
are present more than one time. Then
the transformation do remove the declaration at the child nodes.
Another funny automatism is - if i remove a node
which holds a namespace declaration the first child is inheriting its
declaration.

If you have e.g.
* *<foo xmlns="http://example.com/2008/ns1">
* * *<bar>
* * * *<baz/>
* * *</bar>
* *</foo>
then all three elements are in the namespacehttp://example.com/2008/ns1. Consequently if you copy the bar element
without its foo parent then the serializer has to add a xmlns
declaration to make sure the copied element is still in its namespace.

In the XSLT/XPath 1.0 data model there are namespace nodes which are in
scope for element nodes. And xsl:copyhttp://www.w3.org/TR/xslt#copying
copies these namespace nodes.
With XSLT 2.0http://www.w3.org/TR/xslt20/#shallow-copyyou can specify
whether namespaces are copied but for the namespace of the element
itself that would not prevent the copying of its namespace. If you want
to strip the namespace of an element then you can't use xsl:copy,
instead you need to create a new element e.g.

* *<xsl:template match="pf1:bar"
* * *xmlns:pf1="htt p://example.com/2008/ns1">

* * *<xsl:element name="{local-name()}">
* * * *<xsl:apply-templates select="@* | node()"/>
* * *</xsl:element>

* *</xsl:template>
--

* * * * Martin Honnen
* * * *http://JavaScript.FAQTs.com/
What i want is the following,

<ds:foo xmlns:ds="http://example.com/2008/ns1">
<ds:bar>
<ds:baz/>
</ds:bar>
</ds:foo>

if i copy the node list ds:bar and ignore <ds:foothen ds:bar gets
the declaration of foo.

<ds:bar xmlns:ds="http://example.com/2008/ns1">
<ds:baz/>
</ds:bar>

this is unwanted and i would like to omit this.

second behavior is ....

<ds:foo xmlns:ds="http://example.com/2008/ns1">
<ds:bar xmlns:ds="http://example.com/2008/ns1>
<ds:baz/>
</ds:bar>
</ds:foo>

and i copy the hole structure the result looks like shown below

<ds:foo xmlns:ds="http://example.com/2008/ns1">
<ds:bar>
<ds:baz/>
</ds:bar>
</ds:foo>

but this arent the exact copies of there sources.

Thank You for Help

Wolfram
Jun 27 '08 #3
kl***********@g ooglemail.com wrote:
What i want is the following,

<ds:foo xmlns:ds="http://example.com/2008/ns1">
<ds:bar>
<ds:baz/>
</ds:bar>
</ds:foo>

if i copy the node list ds:bar and ignore <ds:foothen ds:bar gets
the declaration of foo.

<ds:bar xmlns:ds="http://example.com/2008/ns1">
<ds:baz/>
</ds:bar>

this is unwanted and i would like to omit this.
What exactly do you want to omit? As said, if you want to strip the
namespace of an element node then use
<xsl:template match="ds:*"
xmlns:ds="http://example.com/2008/ns1">

<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>

</xsl:template>

but this arent the exact copies of there sources.
XSLT does not work with the source code, it works on the XSLT/XPath data
model.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 27 '08 #4
What happens if you try the following? which is actually
equivalent as far as the __expanded__ namespaces are
concerned:
<ds:foo xmlns:ds="http://example.com/2008/ns1">
<xyz:bar xmlns:xyz="http ://example.com/2008/ns1>
<ds:baz/>
</xyz:bar>
</ds:foo>

kl***********@g ooglemail.com wrote:
>
<ds:foo xmlns:ds="http://example.com/2008/ns1">
<ds:bar xmlns:ds="http://example.com/2008/ns1>
<ds:baz/>
</ds:bar>
</ds:foo>

and i copy the hole structure the result looks like shown below

<ds:foo xmlns:ds="http://example.com/2008/ns1">
<ds:bar>
<ds:baz/>
</ds:bar>
</ds:foo>

but this arent the exact copies of there sources.

Thank You for Help

Wolfram

Jun 27 '08 #5
On 20 Mai, 14:19, Ken Starks <stra...@lampsa cos.demon.co.uk wrote:
What happens if you try the following? which is actually
equivalent as far as the __expanded__ namespaces are
concerned:

<ds:foo xmlns:ds="http://example.com/2008/ns1">
* <xyz:bar xmlns:xyz="http ://example.com/2008/ns1>
* * * * <ds:baz/>
* </xyz:bar>
</ds:foo>

kluge.wolf...@g ooglemail.com wrote:
<ds:foo xmlns:ds="http://example.com/2008/ns1">
* *<ds:bar xmlns:ds="http://example.com/2008/ns1>
* * * <ds:baz/>
* *</ds:bar>
</ds:foo>
and i copy the hole structure the result looks like shown below
<ds:foo xmlns:ds="http://example.com/2008/ns1">
* *<ds:bar>
* * * <ds:baz/>
* *</ds:bar>
</ds:foo>
but this arent the exact copies of there sources.
Thank You for Help
Wolfram- Zitierten Text ausblenden -

- Zitierten Text anzeigen -
Hi Ken

this works
<ds:foo xmlns:ds="http://example.com/2008/ns1">
<xyz:bar xmlns:xyz="http ://example.com/2008/ns1>
<ds:baz/>
</xyz:bar>
</ds:foo>
i think the reason why it works it the new namspace prefix.
But what is going on if redundant namespace declarations occurs.

Thanks

Wolfram
Jun 27 '08 #6
>
Hi Ken

this works
><ds:foo xmlns:ds="http://example.com/2008/ns1">
<xyz:bar xmlns:xyz="http ://example.com/2008/ns1>
<ds:baz/>
</xyz:bar>
</ds:foo>

i think the reason why it works it the new namspace prefix.
But what is going on if redundant namespace declarations occurs.

Thanks

Wolfram
I believe the xslt processor is allowed to do its own
thing, in the case of redundant namespaces, but
I can't say I've read the specifications and seen
it in black and white.
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2169
by: Patrik Carlsson | last post by:
I have a problem using Xerces with a template for a generic page-header getting a sub-tree as argument. The same stylesheet is working flawlessly in IE and Mozilla, though it would be nice to have a result-file to work with too. Here is an example (xerces only get a collapsed string through), any suggestions or current bug-reports are welcome. / Patrik
3
2008
by: Greg Jones | last post by:
Hello, This may be a simple question but difficult to search on since the keywords are so generic. Is there a way, in XSLT, to copy an embedded DTD from the source XML to the target XML? Using 'match="processing-instruction()"' doesn't work. I have been forced to simply output the DTD in the XSLT with <xslt:text>.
12
2047
by: MikeT | last post by:
I have a page that produces little thumbnails of the 3D models it finds in a specified directory (and iterates down through any sub directories). It basically scans each directory for 3D Studio Max files using the filesystemobject and writes an activeX component called iDrop for each file so it can be displayed on the page (and drag-dropped straight into Max). If it happens to find a similarly named XML file in the directory, it loads...
7
2263
by: Harrie | last post by:
Hi group, I want to indent existing XML files so they are more readable (at least to me). At this moment I'm looking at the XML files OpenOffice.org's Writer application produces in it's zipped "SXW" format (and they're one line, probably to save space, which I find hard to read). At first I thought I was going to do it with sed/awk or something like that, but then I remembered the xsl:output element with the indent attribute of XSL and...
4
1401
by: volunteer | last post by:
SIMPLE VERSION OF THE QUESTION: XML_TO_COPY.XML <?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="xsl_that_tries_to_copy_but_does_not_work.xsl"?> <fruits date="20060621"> <fruit name="orange" /> </fruits> COPY_RESULT_THAT_IS_INTENDED.XML orange
1
3195
by: Kenny D | last post by:
Sample input XML... <Publication> <FilingMetadata> <Id>38EA51240E6643208DB1B6D52F779A82</Id> <Cycle>BC</Cycle> </FilingMetadata> <PublicationComponent Role="Main" MediaType="Text"> <TextContentItem> <Language>en-us</Language>
2
2049
by: tschwartz | last post by:
I have an xml document in which elements are hierarchically related to eachother conceptually. Unfortunately, the hierarchical relationship is not modelled in the schema (i.e., the elements are "flattened" in the document". I have a case in which I want to remove a high level element using xslt and want all the related lower-level elements to be removed as well. Is there an easy way to do this in a template? For example, imagine a...
3
2464
by: Andy Dingley | last post by:
>From a thread over in c.i.w.a.h "RFC: From XHTML to HTML via XSLT" http://groups.google.co.uk/group/comp.infosystems.www.authoring.html/msg/f112c230061ffe86 As is well-known, the XSLT HTML output method should generate <br> rather than <br /or <br></br> From: <http://www.w3.org/TR/xslt#section-HTML-Output-Method> : The html output method should not output an end-tag for empty
4
29356
by: mskichu | last post by:
hi, I have a xml in which I want to replace the element(s) value with XSLT Xml message <Message> <case> <party1> <!-- there are other elements -->
0
10215
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
10049
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
9996
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
9865
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
8872
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
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3964
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3564
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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.