|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
Packit |
0f19cf |
version='1.0'>
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
$Id
|
|
Packit |
0f19cf |
********************************************************************
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
This file is part of the XSL DocBook Stylesheet distribution.
|
|
Packit |
0f19cf |
See ../README or http://docbook.sf.net/release/xsl/current/ for
|
|
Packit |
0f19cf |
copyright and other information.
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
******************************************************************** -->
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
<xsl:param name="textdata.default.encoding">iso-8859-1</xsl:param>
|
|
Packit |
0f19cf |
<xsl:param name="current.dir">.</xsl:param>
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
* the DocBook Project (thanks Michael). It makes a listing tree of the
|
|
Packit |
0f19cf |
* external text files referenced in the document, with each reference
|
|
Packit |
0f19cf |
* replaced with corresponding Xinclude instance.
|
|
Packit |
0f19cf |
*
|
|
Packit |
0f19cf |
* <textobject><textdata fileref="foo.txt">
|
|
Packit |
0f19cf |
* <imagedata format="linespecific" fileref="foo.txt">
|
|
Packit |
0f19cf |
* <inlinegraphic format="linespecific" fileref="foo.txt">
|
|
Packit |
0f19cf |
*
|
|
Packit |
0f19cf |
* Those become in the result tree:
|
|
Packit |
0f19cf |
*
|
|
Packit |
0f19cf |
* <listing type="textdata">
|
|
Packit |
0f19cf |
* <xi:include href="foo.txt" parse="text"/></listing>
|
|
Packit |
0f19cf |
* <listing type="imagedata">
|
|
Packit |
0f19cf |
* <xi:include href="foo.txt" parse="text"/></listing>
|
|
Packit |
0f19cf |
* <listing type="inlinegraphic">
|
|
Packit |
0f19cf |
* <xi:include href="foo.txt" parse="text"/></listing>
|
|
Packit |
0f19cf |
*
|
|
Packit |
0f19cf |
* It also works as expected with entityref in place of fileref,
|
|
Packit |
0f19cf |
* and copies over the value of the <textdata> encoding attribute (if
|
|
Packit |
0f19cf |
* found). It is basically intended as an alternative to using the
|
|
Packit |
0f19cf |
* DocBook XSLT Java insertfile() extension.
|
|
Packit |
0f19cf |
-->
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
<xsl:template name="string-replace" >
|
|
Packit |
0f19cf |
<xsl:param name="string"/>
|
|
Packit |
0f19cf |
<xsl:param name="from"/>
|
|
Packit |
0f19cf |
<xsl:param name="to"/>
|
|
Packit |
0f19cf |
<xsl:choose>
|
|
Packit |
0f19cf |
<xsl:when test="contains($string,$from)">
|
|
Packit |
0f19cf |
<xsl:value-of select="substring-before($string,$from)"/>
|
|
Packit |
0f19cf |
<xsl:value-of select="$to"/>
|
|
Packit |
0f19cf |
<xsl:call-template name="string-replace">
|
|
Packit |
0f19cf |
<xsl:with-param name="string" select="substring-after($string,$from)"/>
|
|
Packit |
0f19cf |
<xsl:with-param name="from" select="$from"/>
|
|
Packit |
0f19cf |
<xsl:with-param name="to" select="$to"/>
|
|
Packit |
0f19cf |
</xsl:call-template>
|
|
Packit |
0f19cf |
</xsl:when>
|
|
Packit |
0f19cf |
<xsl:otherwise>
|
|
Packit |
0f19cf |
<xsl:value-of select="$string"/>
|
|
Packit |
0f19cf |
</xsl:otherwise>
|
|
Packit |
0f19cf |
</xsl:choose>
|
|
Packit |
0f19cf |
</xsl:template>
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
<xsl:template name="get.external.filename">
|
|
Packit |
0f19cf |
<xsl:variable name="filename">
|
|
Packit |
0f19cf |
<xsl:choose>
|
|
Packit |
0f19cf |
<xsl:when test="@entityref">
|
|
Packit |
0f19cf |
<xsl:value-of select="unparsed-entity-uri(@entityref)"/>
|
|
Packit |
0f19cf |
</xsl:when>
|
|
Packit |
0f19cf |
<xsl:otherwise>
|
|
Packit |
0f19cf |
<xsl:value-of select="@fileref"/>
|
|
Packit |
0f19cf |
</xsl:otherwise>
|
|
Packit |
0f19cf |
</xsl:choose>
|
|
Packit |
0f19cf |
</xsl:variable>
|
|
Packit |
0f19cf |
<xsl:variable name="absfilename">
|
|
Packit |
0f19cf |
<xsl:choose>
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
contains($filename, ':')">
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
<xsl:value-of select="$filename"/>
|
|
Packit |
0f19cf |
</xsl:when>
|
|
Packit |
0f19cf |
<xsl:otherwise>
|
|
Packit |
0f19cf |
<xsl:value-of select="$current.dir"/>
|
|
Packit |
0f19cf |
<xsl:text>/</xsl:text>
|
|
Packit |
0f19cf |
<xsl:value-of select="$filename"/>
|
|
Packit |
0f19cf |
</xsl:otherwise>
|
|
Packit |
0f19cf |
</xsl:choose>
|
|
Packit |
0f19cf |
</xsl:variable>
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
<xsl:call-template name="string-replace">
|
|
Packit |
0f19cf |
<xsl:with-param name="string" select="$absfilename"/>
|
|
Packit |
0f19cf |
<xsl:with-param name="from" select="' '"/>
|
|
Packit |
0f19cf |
<xsl:with-param name="to" select="'%20'"/>
|
|
Packit |
0f19cf |
</xsl:call-template>
|
|
Packit |
0f19cf |
</xsl:template>
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
imagedata[@format='linespecific']|
|
|
Packit |
0f19cf |
inlinegraphic[@format='linespecific']" mode="lstid">
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
level="any"
|
|
Packit |
0f19cf |
format="1"/>
|
|
Packit |
0f19cf |
</xsl:template>
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
<xsl:template match="textobject[child::textdata[@entityref|@fileref]]">
|
|
Packit |
0f19cf |
<xsl:apply-templates select="textdata"/>
|
|
Packit |
0f19cf |
</xsl:template>
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
<xsl:template match="textdata[@entityref|@fileref]">
|
|
Packit |
0f19cf |
<xsl:variable name="filename">
|
|
Packit |
0f19cf |
<xsl:call-template name="get.external.filename"/>
|
|
Packit |
0f19cf |
</xsl:variable>
|
|
Packit |
0f19cf |
<xsl:variable name="encoding">
|
|
Packit |
0f19cf |
<xsl:choose>
|
|
Packit |
0f19cf |
<xsl:when test="@encoding">
|
|
Packit |
0f19cf |
<xsl:value-of select="@encoding"/>
|
|
Packit |
0f19cf |
</xsl:when>
|
|
Packit |
0f19cf |
<xsl:otherwise>
|
|
Packit |
0f19cf |
<xsl:value-of select="$textdata.default.encoding"/>
|
|
Packit |
0f19cf |
</xsl:otherwise>
|
|
Packit |
0f19cf |
</xsl:choose>
|
|
Packit |
0f19cf |
</xsl:variable>
|
|
Packit |
0f19cf |
<xsl:variable name="lstid">
|
|
Packit |
0f19cf |
<xsl:apply-templates select="." mode="lstid"/>
|
|
Packit |
0f19cf |
</xsl:variable>
|
|
Packit |
0f19cf |
<listing type="textdata" lstid="{$lstid}">
|
|
Packit |
0f19cf |
<xsl:element name="xi:include">
|
|
Packit |
0f19cf |
<xsl:attribute name="href">
|
|
Packit |
0f19cf |
<xsl:value-of select="$filename"/>
|
|
Packit |
0f19cf |
</xsl:attribute>
|
|
Packit |
0f19cf |
<xsl:attribute name="parse">text</xsl:attribute>
|
|
Packit |
0f19cf |
<xsl:attribute name="encoding">
|
|
Packit |
0f19cf |
<xsl:value-of select="$encoding"/>
|
|
Packit |
0f19cf |
</xsl:attribute>
|
|
Packit |
0f19cf |
</xsl:element>
|
|
Packit |
0f19cf |
</listing>
|
|
Packit |
0f19cf |
</xsl:template>
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
match="inlinemediaobject
|
|
Packit |
0f19cf |
[child::imageobject
|
|
Packit |
0f19cf |
[child::imagedata
|
|
Packit |
0f19cf |
[@format = 'linespecific' and
|
|
Packit |
0f19cf |
(@entityref|@fileref)]]]">
|
|
Packit |
0f19cf |
<xsl:apply-templates select="imageobject/imagedata"/>
|
|
Packit |
0f19cf |
</xsl:template>
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
[@format = 'linespecific' and
|
|
Packit |
0f19cf |
(@entityref|@fileref)]">
|
|
Packit |
0f19cf |
<xsl:variable name="filename">
|
|
Packit |
0f19cf |
<xsl:call-template name="get.external.filename"/>
|
|
Packit |
0f19cf |
</xsl:variable>
|
|
Packit |
0f19cf |
<xsl:variable name="lstid">
|
|
Packit |
0f19cf |
<xsl:apply-templates select="." mode="lstid"/>
|
|
Packit |
0f19cf |
</xsl:variable>
|
|
Packit |
0f19cf |
<listing type="imagedata" lstid="{$lstid}">
|
|
Packit |
0f19cf |
<xsl:element name="xi:include">
|
|
Packit |
0f19cf |
<xsl:attribute name="href">
|
|
Packit |
0f19cf |
<xsl:value-of select="$filename"/>
|
|
Packit |
0f19cf |
</xsl:attribute>
|
|
Packit |
0f19cf |
<xsl:attribute name="parse">text</xsl:attribute>
|
|
Packit |
0f19cf |
<xsl:attribute name="encoding">
|
|
Packit |
0f19cf |
<xsl:value-of select="$textdata.default.encoding"/>
|
|
Packit |
0f19cf |
</xsl:attribute>
|
|
Packit |
0f19cf |
</xsl:element>
|
|
Packit |
0f19cf |
</listing>
|
|
Packit |
0f19cf |
</xsl:template>
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
[@format = 'linespecific' and
|
|
Packit |
0f19cf |
(@entityref|@fileref)]">
|
|
Packit |
0f19cf |
<xsl:variable name="filename">
|
|
Packit |
0f19cf |
<xsl:call-template name="get.external.filename"/>
|
|
Packit |
0f19cf |
</xsl:variable>
|
|
Packit |
0f19cf |
<xsl:variable name="lstid">
|
|
Packit |
0f19cf |
<xsl:apply-templates select="." mode="lstid"/>
|
|
Packit |
0f19cf |
</xsl:variable>
|
|
Packit |
0f19cf |
<listing type="inlinegraphic" lstid="{$lstid}">
|
|
Packit |
0f19cf |
<xsl:element name="xi:include">
|
|
Packit |
0f19cf |
<xsl:attribute name="href">
|
|
Packit |
0f19cf |
<xsl:value-of select="$filename"/>
|
|
Packit |
0f19cf |
</xsl:attribute>
|
|
Packit |
0f19cf |
<xsl:attribute name="parse">text</xsl:attribute>
|
|
Packit |
0f19cf |
<xsl:attribute name="encoding">
|
|
Packit |
0f19cf |
<xsl:value-of select="$textdata.default.encoding"/>
|
|
Packit |
0f19cf |
</xsl:attribute>
|
|
Packit |
0f19cf |
</xsl:element>
|
|
Packit |
0f19cf |
</listing>
|
|
Packit |
0f19cf |
</xsl:template>
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
<xsl:template match="node() | @*">
|
|
Packit |
0f19cf |
<xsl:apply-templates select="@* | node()"/>
|
|
Packit |
0f19cf |
</xsl:template>
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
<xsl:template match="/">
|
|
Packit |
0f19cf |
<listings xmlns:xi="http://www.w3.org/2001/XInclude">
|
|
Packit |
0f19cf |
<xsl:apply-templates/>
|
|
Packit |
0f19cf |
</listings>
|
|
Packit |
0f19cf |
</xsl:template>
|
|
Packit |
0f19cf |
|
|
Packit |
0f19cf |
</xsl:stylesheet>
|