Go Back   Velocity Reviews > Newsgroups > XML
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

XML - Copying xml declaration with XSLT

 
Thread Tools Search this Thread
Old 07-13-2006, 12:01 PM   #1
Default 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


Dennis Benzinger
  Reply With Quote
Old 07-13-2006, 12:30 PM   #2
Bjoern Hoehrmann
 
Posts: n/a
Default Re: Copying xml declaration with XSLT

* 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 xslutput settings (e.g.,
you can "change" the character encoding which would require to change
the encoding specified by the xslutput element).
--
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/
  Reply With Quote
Old 07-15-2006, 05:16 AM   #3
Dimitre Novatchev
 
Posts: n/a
Default Re: Copying xml declaration with XSLT

> (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



  Reply With Quote
Old 07-16-2006, 08:43 PM   #4
Dennis Benzinger
 
Posts: n/a
Default Re: Copying xml declaration with XSLT

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
  Reply With Quote
Old 07-17-2006, 05:15 AM   #5
Dimitre Novatchev
 
Posts: n/a
Default Re: Copying xml declaration with XSLT

>> 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"
xmlnssl="http://www.w3.org/1999/XSL/Transform">

<xslutput 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" <> 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



  Reply With Quote
Old 07-18-2006, 02:56 PM   #6
Dennis Benzinger
 
Posts: n/a
Default Re: Copying xml declaration with XSLT

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
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump