• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

xsl:copy and header declarations?

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Marina Popova
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Found today: "How to copy the DOCTYPE value": http://www.dpawson.co.uk/xsl/sect2/N2281.html#d112e51
 
reply
    Bookmark Topic Watch Topic
  • New Topic