473,385 Members | 1,528 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,385 software developers and data experts.

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 4298
kl***********@googlemail.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...@yahoo.dewrote:
kluge.wolf...@googlemail.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="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/
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***********@googlemail.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***********@googlemail.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...@lampsacos.demon.co.ukwrote:
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...@googlemail.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
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...
3
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?...
12
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...
7
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...
4
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...
1
by: Kenny D | last post by:
Sample input XML... <Publication> <FilingMetadata> <Id>38EA51240E6643208DB1B6D52F779A82</Id> <Cycle>BC</Cycle> </FilingMetadata> <PublicationComponent Role="Main" MediaType="Text">...
2
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...
3
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...
4
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 -->
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.