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 October 18th, 2007, 03:05 AM
Authorized User
 
Join Date: Jul 2007
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default Include DOCTYPE declaration

Hi all,
I am using the following code to include document type and entity declaration in the resulting XML.
<xsl:template match="/">
<xsl:text disable-output-escaping="no">
<![CDATA[<!DOCTYPE XYZ PUBLIC "-//ABC//DTD XYZ//EN" "xmain.dtd" [
<!ENTITY par76965_0101.eps SYSTEM "media/par76965_0101.eps" NDATA EPSF>
<!ENTITY par76965_puzzle.eps SYSTEM "media/par76965_puzzle.eps" NDATA EPSF>
]>]]>
</xsl:text>
<xsl:apply-templates select="text()|*|@*"/>
</xsl:template>

Though the problem is that the entity declaration (like <!ENTITY par76965_0101.eps SYSTEM "media/par76965_0101.eps" NDATA EPSF>) changes with the new document and we manually copy/paste them every time into the style sheet.
Is there any other smart way of doing it, I mean any XSLT function which automatically takes these values from XML input to output.

I would prefer to do that with stylesheet only instead of using other scripting languages.

Thanks for guidance in advance.




Pankaj
__________________
Pankaj
 
Old October 18th, 2007, 03:53 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I think you mean disable-output-escaping="yes".

But other than that there is nothing to stop you splitting it into seperate <xsl:text> elements, with <xsl:value-of> bits inbetween.

e.g.

<xsl:text>Filename = </xsl:text><xsl:value-of select="/image/@url"/><xsl:text>.</xsl:text>



/- Sam Judson : Wrox Technical Editor -/
 
Old October 18th, 2007, 05:45 AM
Authorized User
 
Join Date: Jul 2007
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Sam. Just diverting from what you are suggesting, I've just gone thru the documents and found dtd declaration can be done with

<xsl:output method="xml" indent="no" media-type="text/xml" encoding="UTF-8" doctype-system="xmain.dtd" doctype-public="-//XYZ//DTD main//EN"/>

which gives me desired output as
<!DOCTYPE main PUBLIC "-//XYZ//DTD main/EN" "xmain.dtd">
 but what about entity declarations below:
<!ENTITY par76965_0101.eps SYSTEM "media/par76965_0101.eps" NDATA EPSF>
<!ENTITY par76965_puzzle.eps SYSTEM "media/par76965_puzzle.eps" NDATA EPSF>

Can you throw some light on it. Secondly, could you please elaborate what do you mean by <xsl:text>Filename = </xsl:text><xsl:value-of select="/image/@url"/><xsl:text>.</xsl:text>,
does that mean I need to change <xsl:text> every time for every xml document.

Below is the output I am looking for, where entity declaration varies:
<!DOCTYPE main PUBLIC "-//XYZ//DTD main/EN" "xmain.dtd" [
<!ENTITY par76965_0101.eps SYSTEM "media/par76965_0101.eps" NDATA EPSF>
<!ENTITY par76965_puzzle.eps SYSTEM "media/par76965_puzzle.eps" NDATA EPSF>

Thanks,
Pankaj








Pankaj
 
Old October 18th, 2007, 06:10 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You said you wanted to change the entity declaration based on the input XML, so thats what I mentioned. You didn't provide any input xml for me to base an example on so I made some up in my head.

Code:
<media>
 <pic url="par76965_0101.eps"/>
 <pic url="par76965_puzzle.eps"/>
</media>
Code:
<xsl:template match="/">
<xsl:text disable-output-escaping="yes">
<![CDATA[<!DOCTYPE XYZ PUBLIC "-//ABC//DTD XYZ//EN" "xmain.dtd" [
]]></xsl:text>
<xsl:for-each select="media/pic">
<xsl:text disable-output-escaping="yes"><![CDATA[<!ENTITY ]]></xsl:text>
<xsl:value-of select="@url"/>
<xsl:text> SYSTEM "media/</xsl:text>
<xsl:value-of select="@url"/>
<xsl:text disable-output-escaping="yes"><![CDATA[" NDATA EPSF>
]]></xsl:text>
</xsl:for-each>
<xsl:text disable-output-escaping="yes"><![CDATA[]>]]></xsl:text>
</xsl:template>
/- Sam Judson : Wrox Technical Editor -/
 
Old October 18th, 2007, 07:09 AM
Authorized User
 
Join Date: Jul 2007
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I understand what u meant of using "for-each" and "value-of"
But I do not have anything like

<media>
 <pic url="par76965_0101.eps"/>
 <pic url="par76965_puzzle.eps"/>
</media>

My xml input starts:

<!DOCTYPE XYZ PUBLIC "-//ABC//DTD XYZ//EN" "xmain.dtd" [
<!ENTITY par76965_0101.eps SYSTEM "media/par76965_0101.eps" NDATA EPSF>
<!ENTITY par76965_puzzle.eps SYSTEM "media/par76965_puzzle.eps" NDATA EPSF>]>

And I want to retain this info in transformed XML.
Apologies, if I am not able to make myself clear and having one of those days.
Pankaj



Pankaj
 
Old October 18th, 2007, 08:01 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Ah, right.

In that case you are stuck, unless you fancy doing what Michael mentioned elsewhere and using the new unparsed-text() function in XSLT 2.0 or some other vendor specific extension for loading the input file in (as a separate action) as plain text.

/- Sam Judson : Wrox Technical Editor -/
 
Old October 18th, 2007, 08:46 AM
Authorized User
 
Join Date: Jul 2007
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yeah I understand. I think I need look other way to get this done for me.

Thanks anyway.

Pankaj





Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying DOCTYPE madanshah16 XSLT 1 August 18th, 2007 12:23 PM
DOCTYPE for XHTML 1.1 complaince crmpicco HTML Code Clinic 14 July 22nd, 2006 09:24 AM
difference between include file & include virtual crmpicco Classic ASP Basics 2 January 23rd, 2006 11:50 AM
Why to use <!Doctype...? rupen HTML Code Clinic 2 October 25th, 2005 04:55 AM
doctype 4.01 anshul HTML Code Clinic 3 December 28th, 2004 06:24 AM





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