473,513 Members | 2,749 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Copying xml declaration with XSLT

How can I copy the xml declaration from one document to another document
using XSLT?

(Use case: I have a xml document where I just want to add a processing
instruction without modifing the rest of the document)
Thanks,
Dennis
Jul 13 '06 #1
5 2167
* Dennis Benzinger wrote in comp.text.xml:
>How can I copy the xml declaration from one document to another document
using XSLT?

(Use case: I have a xml document where I just want to add a processing
instruction without modifing the rest of the document)
That's not possible without using processor-specific extensions; in the
XPath data model, which XSLT operates on, this information is lost and
re-created based on among other things the xsl:output settings (e.g.,
you can "change" the character encoding which would require to change
the encoding specified by the xsl:output element).
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Jul 13 '06 #2
(Use case: I have a xml document where I just want to add a processing
instruction without modifing the rest of the document)
The xml declaration is not a processing instruction. A processing
instruction is represented in the XML Infoset and can easily be copied from
one document to another.

Cheers,
Dimitre Novatchev
"Dennis Benzinger" <De**************@gmx.netwrote in message
news:44********@news.uni-ulm.de...
How can I copy the xml declaration from one document to another document
using XSLT?

(Use case: I have a xml document where I just want to add a processing
instruction without modifing the rest of the document)
Thanks,
Dennis

Jul 15 '06 #3
Dimitre Novatchev wrote:
>(Use case: I have a xml document where I just want to add a processing
instruction without modifing the rest of the document)

The xml declaration is not a processing instruction.
Yes, I know that. But I don't want to copy the xml declaration, I want
to add a processing instruction.
A processing instruction is represented in the XML Infoset and can easily
be copied from one document to another.
[...]
So please show me how.

Dennis
Jul 16 '06 #4
>A processing instruction is represented in the XML Infoset and can easily
>be copied from one document to another.
[...]

So please show me how.
Use the <xsl:copy-ofinstruction.

Here's a simple example:

This transformation:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output omit-xml-declaration="yes"/>

<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>

<xsl:template match="processing-instruction()">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>

when applied on this source xml document:

<t>
<?PI xxx="yyy" ?>
</t>

produces this result:

<t>
<?PI xxx="yyy" ?>
</t>

The processing instruction matched by the 2nd (last template) and this
template is selected for processing it. The action is simply to copy the
current node (the processing instruction) to the output.
Hope this helps.

Cheers,
Dimitre Novatchev
"Dennis Benzinger" <De**************@gmx.netwrote in message
news:44********@news.uni-ulm.de...
Dimitre Novatchev wrote:
>>(Use case: I have a xml document where I just want to add a processing
instruction without modifing the rest of the document)

The xml declaration is not a processing instruction.

Yes, I know that. But I don't want to copy the xml declaration, I want to
add a processing instruction.
>A processing instruction is represented in the XML Infoset and can easily
be copied from one document to another.
[...]

So please show me how.

Dennis

Jul 17 '06 #5
Dennis Benzinger wrote:
Dimitre Novatchev wrote:
>>(Use case: I have a xml document where I just want to add a
processing instruction without modifing the rest of the document)

The xml declaration is not a processing instruction.

Yes, I know that. But I don't want to copy the xml declaration, I want
to add a processing instruction.
Must have been quite confused when I wrote this. Of course I want to
copy a xml declaration like I wrote in my first post. After all I want
to add a processing instruction to a xml document without modifing the
rest of the document. But as Bjoern Hoermann wrote that's not possible
with XSLT. Maybe XSLT 2.0 helps?
>A processing instruction is represented in the XML Infoset and can easily
be copied from one document to another.
[...]

So please show me how.

Dennis
Thanks to Dimitre Novatchev for anwsering my useless question.
Dennis
Jul 18 '06 #6

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

Similar topics

3
3076
by: Sarah Haskins | last post by:
I have a few questions about this problem I'm having involving XML, DTD, and XSL. I'm working with this DTD which defines a stylesheet, as such... <?xml version="1.0" encoding="UTF-8"?>...
1
2686
by: Ken Larson | last post by:
I have a question about using XSL to extract information from an SVG (XML) file that has a DOCTYPE/DTD declaration. I am able to do this successfully if I write my own SVG files without such a...
2
11396
by: Manoj G | last post by:
Hello, I believe there is no way to remove the default namespace declaration (For eg <DataSet xmlns="something">.... ) on an XmlNode object directly through DOM. So, what is the best way to...
1
1341
by: George1776 | last post by:
Background: I have taken an excel spreadsheet with the formatting I want, saved it as XML, then converted it to an XSL document to use it as a sort of template. Added some for-each select...
2
2318
by: intrepidca | last post by:
When I try to translate an XML file (using org.apache.xalan.xslt.Process) that has a DOCTYPE declaration, I only get the <?xml ...?> processing instruction in the output file. I get no error...
3
1394
by: Al Hatch | last post by:
XSLT fails when the XML file contains this top-level declaration: <?xml version="1.0" encoding="UTF-8" standalone="no" ?> <P2Main xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"...
0
1035
by: Omatase | last post by:
I have an xslt file I need to open at runtime. Here is my configuration: main assembly (dll) |-----xslt file unit test assembly I have a reference to my main assembly in my unit test...
8
3696
by: Simon Brooke | last post by:
I have a DTD. If I declare it at the top of my XML file, as so: <!DOCTYPE application PUBLIC "-//CYGNETS//DTD ADL 0.1//EN" "http://libs.cygnets.co.uk/adl/unstable/ADL/schemas/adl-0.dtd"> then...
3
2370
by: shifflav | last post by:
I'm not sure if this would classify as an XML or ASP question: I'm redoing someone's website who sells various products. I've decided to teach myself XSLT and re-do the entire site using XML. ...
0
7259
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
7380
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,...
0
7535
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...
1
7098
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...
0
5683
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,...
0
4745
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...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1592
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 ...
0
455
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...

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.