Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 21st, 2003, 02:46 AM
Registered User
 
Join Date: Jul 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default retaining ENTITY declarations

another problem, how do i retain the ENTITY declarations in an
XML-to-XML conversion using XSLT?

<xsl:output doctype-public="-//arvin//DTD myDocument v1.0//EN//XML" doctype-system="myDTD.dtd"/>
  will output
<!DOCTYPE myDocument PUBLIC "-//arvin//DTD myDocument v1.0//EN//XML" SYSTEM "myDTD.dtd">.

but i need:
<!DOCTYPE myDocument PUBLIC "-//arvin//DTD myDocument v1.0//EN//XML" SYSTEM "myDTD.dtd" [
<!ENTITY abc SYSTEM abc NDATA image>
<!ENTITY xyz SYSTEM xyz NDATA image>
]>

how can make this happen?

Thanks! :)
 
Old July 22nd, 2003, 12:54 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to armmarti
Default

There is no way to output entity declarations by using "pure" XSLT features (an element in XSLT namespace, for example). The only way to solve the problem is to use "disable-output-escaping" attribute of the element "xsl:value-of" to output a markup.
By the way, in DOCTYPE declaration "SYSTEM" is not permitted if you want to specify both public and system IDs (as defined in the XML spec). And in your entity declarations the system IDs must be in quotation marks.
So, the code is:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:variable name="doc-type">
        <![CDATA[<!DOCTYPE myDocument PUBLIC "-//arvin//DTD myDocument v1.0//EN//XML" "myDTD.dtd" [
            <!ENTITY abc SYSTEM "abc" NDATA image>
            <!ENTITY xyz SYSTEM "xyz" NDATA image>]>]]>
    </xsl:variable>    

    <xsl:template match="/">
        <xsl:value-of select="$doc-type" disable-output-escaping="yes"/>
        <myDocument>
            content
        </myDocument>
    </xsl:template>
</xsl:stylesheet>
It's assumed, of course, that myDTD.dtd and output.xml are in the same folder.

I hope this will help you.

Regards,
Armen
 
Old July 22nd, 2003, 10:47 PM
Registered User
 
Join Date: Jul 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Armen. But my problem was i have several XML files (with ENTITY declarations) that i need to transform into differently-tagged XML files but i need to retain those ENTITY declarations within their respective "transformed" XML files.
 
Old July 23rd, 2003, 01:51 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to armmarti
Default

I can offer one solution, though it needs to change your source XML documents slightly:

You can add some element, say having element type "doc-type", to XML sources, like this:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE myDocument PUBLIC "-//arvin//DTD myDocument v1.0//EN//XML" "myDTD.dtd" [
<!ENTITY abc SYSTEM "abc" NDATA image>
<!ENTITY xyz SYSTEM "xyz" NDATA image>]>
<root>

  <doc-type>
    <![CDATA[<!DOCTYPE myDocument PUBLIC "-//arvin//DTD myDocument v1.0//EN//XML" "myDTD.dtd" [
             <!ENTITY abc SYSTEM "abc" NDATA image>
             <!ENTITY xyz SYSTEM "xyz" NDATA image>]>]]>  
  </doc-type>
  <!--
   ...
  --> 
</root>
Then you can use "disable-output-escaping" attribute again to output the stuff as markup.

Since you have no access to unparsed entity declarations in the XSLT data model, the only way(at least, the most obvious way for me) you can pass your entity-declarations through XSLT transformation to output XML document is to wrap them into some element.

Regards,
Armen





Similar Threads
Thread Thread Starter Forum Replies Last Post
When to use NEW in declarations LarryMoore BOOK: Beginning Microsoft Visual Basic 2008 ISBN: 978-0-470-19134-7 8 September 24th, 2008 04:02 PM
Why do API Declarations Incr. .EXE size? BrianWren Pro VB 6 6 December 21st, 2007 03:23 PM
Where are my control declarations? Ron Howerton ASP.NET 2.0 Basics 13 December 6th, 2007 03:11 PM
Variable Declarations New2ASPnet General .NET 1 July 30th, 2004 09:49 AM
Difference between Entity and Entity type arshad mahmood C++ Programming 0 May 8th, 2004 12:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.