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
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).]
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
Leverager of our synergies
Joined: Aug 26, 2000
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!
Joined: Jul 20, 2001
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