![]() |
|
|
|||||||
![]() |
XML - Copying xml declaration with XSLT |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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 Dennis Benzinger |
|
|
|
|
#2 |
|
Posts: n/a
|
* 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 you can "change" the character encoding which would require to change the encoding specified by the xsl -- Björn Höhrmann · private.php?do=newpm&u= · 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/ |
|
|
|
#3 |
|
Posts: n/a
|
> (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" <> wrote in message news:44b627ed$... > 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 |
|
|
|
#4 |
|
Posts: n/a
|
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 |
|
|
|
#5 |
|
Posts: n/a
|
>> 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-of> instruction. Here's a simple example: This transformation: <xsl:stylesheet version="1.0" xmlns <xsl <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" <> wrote in message news:44ba96d9$... > 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 |
|
|
|
#6 |
|
Posts: n/a
|
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 |
|