aspose file tools*
The moose likes XML and Related Technologies and the fly likes xsl:copy and header declarations? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "xsl:copy and header declarations?" Watch "xsl:copy and header declarations?" New topic
Author

xsl:copy and header declarations?

Marina Popova
Greenhorn

Joined: Jul 20, 2001
Posts: 11
Hi!
I guess my question is a beginner one...
I'm trying to modify an XML document slightly, changing a few elements values only and leaving others unchanged. I do this as following: (Sorry, had to delete all angle brackets, as they are not allowed here ...)
xsl:template match="node()"
xsl:copy
xsl:apply-templates/
/xsl:copy
/xsl:template
xsl:template match="//specificElement"
specificElement
xsl:value-of select="newValue"/
/specificElement
/xsl:template
It works fine with one exception: first two lines with XML and DOCTYPE declarations are not copied into the result XML file:
?xml version="1.0" standalone="no"?
!DOCTYPE com SYSTEM "com.dtd"
Is there any way to copy these elements also??
Thank you very much!
Marina

Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
Ho Marina!
You need to use <xsl utput> element:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl utput standalone="no" doctype-system="com.dtd"/>
By the way, you do not need to delete angle brackets, in this foum HTML is turned off, so no tags will be interpreted.

[This message has been edited by Mapraputa Is (edited July 21, 2001).]


Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
Marina Popova
Greenhorn

Joined: Jul 20, 2001
Posts: 11
Thanks a lot for the advise, Mapraputa!
Unfortunately, it won't solve my problem, I'm afraid...
As I understand, the <xsl utput ... > line is hardcoded in the stylesheet file - which means that I have to hard code a name of the DTD file also. The problem is that I need to process many different xml files with this stylesheet and all these files have different DTDs (but they all have this one element that the stylesheet will process...). So that I cannot hardcode the DTD name in the <xsl utput ...> line...
Is there any way to get around this??
Thanks a again!
Marina
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
Then it is much worse...
I suspected that there is no way to do so, because DTD's do not use XML syntax and are not parsed by the parser. When XSLT processor receives an input tree built by the parser, DTD's declarations are already applied and forgotten. I asked your question "if there is any way to copy DOCTYPE declaration" in another forum and here is what guru said:
"No, there isn't. The DOCTYPE declaration isn't part of the tree model built by the parser."
As I can imagine, all possible workarounds are outside of XSLT. You can read your XML as a text file in Java program, for example, save DOCTYPE declaration in a string, then call XSLT transformation, save its result in another string and then combine them. If anybody has better ideas, please, post them here!
Marina Popova
Greenhorn

Joined: Jul 20, 2001
Posts: 11
Thanks a lot for your answer!
Yes, I think the only choice here is to create a header as a separate file and concatenate it with the result xml file...
Thanks!
Marina
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
Found today: "How to copy the DOCTYPE value": http://www.dpawson.co.uk/xsl/sect2/N2281.html#d112e51
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: xsl:copy and header declarations?