source: clfs-sysroot/BOOK/stylesheets/lfs-xsl/docbook-xsl-snapshot/common/insertfile.xsl@ 90e4737

Last change on this file since 90e4737 was a18aefd, checked in by Manuel Canales Esparcia <manuel@…>, 17 years ago

Added lfs-xsl stylesheets.

  • Property mode set to 100644
File size: 3.8 KB
RevLine 
[a18aefd]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'>
5
6<!-- ********************************************************************
7 $Id$
8 ********************************************************************
9
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.
13
14 ******************************************************************** -->
15
16<xsl:param name="textdata.default.encoding"></xsl:param>
17
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. -->
34
35<!-- ==================================================================== -->
36
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>
47
48<!-- ==================================================================== -->
49
50<xsl:template match="textobject[child::textdata[@entityref|@fileref]]">
51 <xsl:apply-templates select="textdata"/>
52</xsl:template>
53
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>
70
71<!-- ==================================================================== -->
72
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>
81
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>
90
91<!-- ==================================================================== -->
92
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>
101
102<!-- ==================================================================== -->
103
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>
110
111</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.