Jitterbug no more.
[fvwm.git] / doc / docbook-xsl / common / insertfile.xsl
blobc3a59787f3bc869353da6079e9e26e962303f63b
1 <?xml version='1.0'?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 xmlns:xi="http://www.w3.org/2001/XInclude"
4 version='1.0'>
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. -->
21 <!-- * -->
22 <!-- * <textobject><textdata fileref="foo.txt"> -->
23 <!-- * <imagedata format="linespecific" fileref="foo.txt"> -->
24 <!-- * <inlinegraphic format="linespecific" fileref="foo.txt"> -->
25 <!-- * -->
26 <!-- * Those become: -->
27 <!-- * -->
28 <!-- * <xi:include href="foo.txt" parse="text"/> -->
29 <!-- * -->
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">
38 <xsl:choose>
39 <xsl:when test="@entityref">
40 <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
41 </xsl:when>
42 <xsl:otherwise>
43 <xsl:value-of select="@fileref"/>
44 </xsl:otherwise>
45 </xsl:choose>
46 </xsl:template>
48 <!-- ==================================================================== -->
50 <xsl:template match="textobject[child::textdata[@entityref|@fileref]]">
51 <xsl:apply-templates select="textdata"/>
52 </xsl:template>
54 <xsl:template match="textdata[@entityref|@fileref]">
55 <xsl:variable name="filename">
56 <xsl:call-template name="get.external.filename"/>
57 </xsl:variable>
58 <xsl:variable name="encoding">
59 <xsl:choose>
60 <xsl:when test="@encoding">
61 <xsl:value-of select="@encoding"/>
62 </xsl:when>
63 <xsl:otherwise>
64 <xsl:value-of select="$textdata.default.encoding"/>
65 </xsl:otherwise>
66 </xsl:choose>
67 </xsl:variable>
68 <xi:include href="{$filename}" parse="text" encoding="{$encoding}"/>
69 </xsl:template>
71 <!-- ==================================================================== -->
73 <xsl:template
74 match="inlinemediaobject
75 [child::imageobject
76 [child::imagedata
77 [@format = 'linespecific' and
78 (@entityref|@fileref)]]]">
79 <xsl:apply-templates select="imageobject/imagedata"/>
80 </xsl:template>
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"/>
87 </xsl:variable>
88 <xi:include href="{$filename}" parse="text" encoding="{$textdata.default.encoding}"/>
89 </xsl:template>
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"/>
98 </xsl:variable>
99 <xi:include href="{$filename}" parse="text" encoding="{$textdata.default.encoding}"/>
100 </xsl:template>
102 <!-- ==================================================================== -->
104 <!-- * copy everything else into result tree as-is -->
105 <xsl:template match="node() | @*">
106 <xsl:copy>
107 <xsl:apply-templates select="@* | node()"/>
108 </xsl:copy>
109 </xsl:template>
111 </xsl:stylesheet>