xsl-list
[Top] [All Lists]

Re: [xsl] Generating <!ENTITY list

2009-03-18 13:48:40
At 2009-03-18 17:53 +0530, Ganesh Babu N wrote:
Dear All,

I am having

input:

<graphic file="1.jpg"/>
<graphic file="2.jpg"/>

I need to create <!ENTITY List inside the DOCTYPE. Is the any way i
can achieve this using XSL. I am using ver 2.0 and saxon9.

The output should be :

<!DOCTYPE article
[
<!ENTITY gr1 SYSTEM "1.jpg" NDATA IMAGE>
<!ENTITY gr2 SYSTEM "2.jpg" NDATA IMAGE>
]>

Absolutely there is a way ... in both XSLT 1.0 and 2.0 ... this is a use case I tell students justifies the dangerous disable-output-escaping= attribute.

I say "dangerous" because it does not help when the output tree from the transformation is used as the input tree for a subsequent process. It is only helpful when you are serializing your output tree into output angle-bracket syntax, and the processor you are using supports serialization.

I hope the example below for both XSLT 1.0 and 2.0 helps.

. . . . . . . . Ken

t:\ftemp>type ganesh.xml
<graphics>
 <graphic file="1.jpg"/>
 <graphic file="2.jpg"/>
</graphics>

t:\ftemp>call xslt ganesh.xml ganesh.xsl
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE article
[
<!ENTITY gr1 SYSTEM "1.jpg" NDATA IMAGE>
<!ENTITY gr2 SYSTEM "2.jpg" NDATA IMAGE>
]>
<article><!--The article goes here--></article>
t:\ftemp>type ganesh.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                version="1.0">

<xsl:output indent="yes"/>

<xsl:template match="/">
  <xsl:text disable-output-escaping="yes"><![CDATA[
<!DOCTYPE article
[
]]></xsl:text>
  <xsl:for-each select="/*/graphic">
    <xsl:value-of disable-output-escaping="yes"
                  select="concat('&lt;!ENTITY gr',
                                 substring-before(@file,'.'),
                                 ' SYSTEM &#34;',@file,
                                 '&#34; NDATA IMAGE>')"/>
    <xsl:text>
</xsl:text>
  </xsl:for-each>
  <xsl:text disable-output-escaping="yes">]>
</xsl:text>
   <article>
     <xsl:comment>The article goes here</xsl:comment>
   </article>
</xsl:template>

</xsl:stylesheet>

t:\ftemp>


--
XSLT/XSL-FO/XQuery training in Los Angeles (New dates!) 2009-06-08
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>