473,670 Members | 2,307 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 2177
* 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****@h oehrmann.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:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">

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

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

<xsl:template match="processi ng-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
3096
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"?> <?xml-stylesheet type="text/xsl" href="abc-xsl.xsl"?> <!ELEMENT ABCMessage (Tag1, Tag2, Tag3, Tag4, Tag5, Tag6, Tag7, Tag8*)> <!ATTLIST ABCMessage
1
2695
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 declaration. However, I would like to extract some parts of an SVG file exported by illustrator. When I try this, my XSL file is no longer able to access the nodes in the SVG document properly - somehow related to the DOCTYPE/DTD declaration. ...
2
11402
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 remove it 1) XSLT templates? 2) Copy all the contents into a new node and leave out the namespace? Use this node node in lieu of the old one?
1
1354
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 functionality and am able to populate it with data from good old Northwind. Everything is working great except one exasperating problem: the final XML document does not include an xml declaration (i.e. <?xml version="1.0"?>). It seems that the...
2
2330
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 messages. If I remove the DOCTYPE declaration it works fine. I have checked that the XML file is valid according to the DTD (using xmllint) and that checks out. Here are snippets from the XML and the XSL files and debugging output from xalan: the...
3
1398
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" xmlns="urn:schemas-Professional-Plug-in:P2:ClipMetadata:v3.0"> <ClipName>0001FM</ClipName> </P2Main> However, XSLT succeeds when I modify the XML declaration to this:
0
1050
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 assembly. Both projects share a solution. I am trying to test a method that transforms some XML based on a stylesheet I have in the main assembly. The xslt
8
3707
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 editors such as emacs (PSGML), Oxygen and Microsoft Visual Studio parse the DTD and offer me context sensitive menus to insert the right elements and the right attributes in the right places. So the DTD really is there and really can be parsed....
3
2381
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. I'm creating .aspx files with which will include an XML file of the products at the bottom of each page. To do this, I have the following code in my .aspx file where the XML data goes: <asp:Xml runat="server" documentSource="more.xml"...
0
8469
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, 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...
0
8903
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...
1
8592
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
7419
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
5684
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();...
0
4211
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4391
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2800
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
1794
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.