2 <xsl:stylesheet xmlns:
xsl=
"http://www.w3.org/1999/XSL/Transform"
3 xmlns:
xi=
"http://www.w3.org/2001/XInclude"
6 <!-- ********************************************************************
7 $Id: insertfile.xsl,v 1.1 2007/03/10 05:14:55 scott Exp $
8 ********************************************************************
10 This file is part of the XSL DocBook Stylesheet distribution.
11 See ../README or http://docbook.sf.net/release/xsl/current/ for
12 copyright and other information.
14 ******************************************************************** -->
16 <xsl:param name=
"textdata.default.encoding"></xsl:param>
18 <!-- * This stylesheet makes a copy of a source tree, replacing all -->
19 <!-- * instances of the following with corresponding Xinclude instances -->
20 <!-- * in the result tree. -->
22 <!-- * <textobject><textdata fileref="foo.txt"> -->
23 <!-- * <imagedata format="linespecific" fileref="foo.txt"> -->
24 <!-- * <inlinegraphic format="linespecific" fileref="foo.txt"> -->
26 <!-- * Those become: -->
28 <!-- * <xi:include href="foo.txt" parse="text"/> -->
30 <!-- * It also works as expected with entityref in place of fileref, -->
31 <!-- * and copies over the value of the <textdata>“encoding” atrribute (if -->
32 <!-- * found). It is basically intended as an alternative to using the -->
33 <!-- * DocBook XSLT Java insertfile() extension. -->
35 <!-- ==================================================================== -->
37 <xsl:template name=
"get.external.filename">
39 <xsl:when test=
"@entityref">
40 <xsl:value-of select=
"unparsed-entity-uri(@entityref)"/>
43 <xsl:value-of select=
"@fileref"/>
48 <!-- ==================================================================== -->
50 <xsl:template match=
"textobject[child::textdata[@entityref|@fileref]]">
51 <xsl:apply-templates select=
"textdata"/>
54 <xsl:template match=
"textdata[@entityref|@fileref]">
55 <xsl:variable name=
"filename">
56 <xsl:call-template name=
"get.external.filename"/>
58 <xsl:variable name=
"encoding">
60 <xsl:when test=
"@encoding">
61 <xsl:value-of select=
"@encoding"/>
64 <xsl:value-of select=
"$textdata.default.encoding"/>
68 <xi:include href=
"{$filename}" parse=
"text" encoding=
"{$encoding}"/>
71 <!-- ==================================================================== -->
74 match=
"inlinemediaobject
77 [@format = 'linespecific' and
78 (@entityref|@fileref)]]]">
79 <xsl:apply-templates select=
"imageobject/imagedata"/>
82 <xsl:template match=
"imagedata
83 [@format = 'linespecific' and
84 (@entityref|@fileref)]">
85 <xsl:variable name=
"filename">
86 <xsl:call-template name=
"get.external.filename"/>
88 <xi:include href=
"{$filename}" parse=
"text" encoding=
"{$textdata.default.encoding}"/>
91 <!-- ==================================================================== -->
93 <xsl:template match=
"inlinegraphic
94 [@format = 'linespecific' and
95 (@entityref|@fileref)]">
96 <xsl:variable name=
"filename">
97 <xsl:call-template name=
"get.external.filename"/>
99 <xi:include href=
"{$filename}" parse=
"text" encoding=
"{$textdata.default.encoding}"/>
102 <!-- ==================================================================== -->
104 <!-- * copy everything else into result tree as-is -->
105 <xsl:template match=
"node() | @*">
107 <xsl:apply-templates select=
"@* | node()"/>