techtonik Mon Nov 1 11:33:48 2004 EDT
Modified files:
/phpdoc/xsl common.xsl
Log:
more advanced newline strip template for programlistings
what preserves first line indentation
http://cvs.php.net/diff.php/phpdoc/xsl/common.xsl?r1=1.13&r2=1.14&ty=u
Index: phpdoc/xsl/common.xsl
diff -u phpdoc/xsl/common.xsl:1.13 phpdoc/xsl/common.xsl:1.14
--- phpdoc/xsl/common.xsl:1.13 Mon Nov 1 07:16:55 2004
+++ phpdoc/xsl/common.xsl Mon Nov 1 11:33:47 2004
@@ -1,196 +1,248 @@
-<?xml version="1.0" encoding="iso-8859-1"?>
-<!--
-
- common.xsl: Common customizations for all formats
-
- $Id: common.xsl,v 1.13 2004/11/01 12:16:55 techtonik Exp $
-
--->
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- version="1.0">
-
-
-<!-- Colorize background for programlisting and screens
- will go into CSS probably in next DocBook version -->
-<xsl:param name="shade.verbatim" select="1"/>
-
-
-<!-- *************** TUNE FUNCTION REFERENCE PAGES **************** -->
-<!-- Generate title from function name instead of word "NAME" in title -->
-<xsl:param name="refentry.generate.name" select="'0'"/>
-<xsl:param name="refentry.generate.title" select="'1'"/>
-
-<!-- Turn off separators on reference and refentry pages -->
-<xsl:param name="refentry.separator" select="'0'"/>
-<xsl:template name="reference.titlepage.separator"/>
-<!-- FIX: temporary till also this is in std.-distrib. -->
-<xsl:template match="reference/titleabbrev"/>
-
-
-<!-- Load VERSION INFORMATION into variable -->
-<xsl:param name="version" select="document('version.xml')/versions"/>
-
-
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!--
+
+ common.xsl: Common customizations for all HTML formats
+
+ $Id: common.xsl,v 1.14 2004/11/01 16:33:47 techtonik Exp $
+
+-->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ version="1.0">
+
+
+<!-- Colorize background for programlisting and screens
+ will go into CSS probably in next DocBook version -->
+<xsl:param name="shade.verbatim" select="1"/>
+
+
+
+<!-- *************** TUNE FUNCTION REFERENCE PAGES **************** -->
+<!-- Generate title from function name instead of word "NAME" in title -->
+<xsl:param name="refentry.generate.name" select="'0'"/>
+<xsl:param name="refentry.generate.title" select="'1'"/>
+
+<!-- Turn off separators on reference and refentry pages -->
+<xsl:param name="refentry.separator" select="'0'"/>
+<xsl:template name="reference.titlepage.separator"/>
+<!-- FIX: temporary till also this is in std.-distrib. -->
+<xsl:template match="reference/titleabbrev"/>
+
+
+<!-- Load VERSION INFORMATION into variable -->
+<xsl:param name="version" select="document('version.xml')/versions"/>
+
+
<!-- We do not want semicolon at the end of prototype and our own style
of square brackets for optional parameters -->
-<xsl:template match="methodsynopsis">
- <xsl:apply-templates />
-</xsl:template>
-
-<xsl:template match="methodsynopsis/type">
- <xsl:apply-templates />
- <xsl:text> </xsl:text>
-</xsl:template>
-
-<xsl:template match="methodsynopsis/void">
+<xsl:template match="methodsynopsis">
+ <xsl:apply-templates />
+</xsl:template>
+
+<xsl:template match="methodsynopsis/type">
+ <xsl:apply-templates />
+ <xsl:text> </xsl:text>
+</xsl:template>
+
+<xsl:template match="methodsynopsis/void">
<xsl:text> (void)</xsl:text>
-</xsl:template>
-
-<xsl:template match="methodparam/type">
- <xsl:apply-templates />
- <xsl:text> </xsl:text>
-</xsl:template>
-
-<xsl:template match="methodparam/parameter">
- <xsl:apply-templates />
-</xsl:template>
-
-<xsl:template match="methodparam">
- <xsl:if test="preceding-sibling::methodparam=false()">
- <xsl:text> (</xsl:text>
- <xsl:if test="@choice='opt'">
- <xsl:text>[</xsl:text>
- </xsl:if>
- </xsl:if>
- <xsl:apply-templates />
- <xsl:choose>
- <xsl:when test="following-sibling::methodparam">
- <xsl:choose>
- <xsl:when
test="following-sibling::methodparam[position()=1]/attribute::choice[.='opt']">
- <xsl:text> [, </xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <xsl:text>, </xsl:text>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <xsl:otherwise>
+</xsl:template>
+
+<xsl:template match="methodparam/type">
+ <xsl:apply-templates />
+ <xsl:text> </xsl:text>
+</xsl:template>
+
+<xsl:template match="methodparam/parameter">
+ <xsl:apply-templates />
+</xsl:template>
+
+<xsl:template match="methodparam">
+ <xsl:if test="preceding-sibling::methodparam=false()">
+ <xsl:text> (</xsl:text>
+ <xsl:if test="@choice='opt'">
+ <xsl:text>[</xsl:text>
+ </xsl:if>
+ </xsl:if>
+ <xsl:apply-templates />
+ <xsl:choose>
+ <xsl:when test="following-sibling::methodparam">
+ <xsl:choose>
+ <xsl:when
test="following-sibling::methodparam[position()=1]/attribute::choice[.='opt']">
+ <xsl:text> [, </xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>, </xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:when>
+ <xsl:otherwise>
<xsl:for-each select="preceding-sibling::methodparam">
<xsl:if test="attribute::choice[.='opt']">
<xsl:text>]</xsl:text>
</xsl:if>
- </xsl:for-each>
- <xsl:if test="self::methodparam/attribute::choice[.='opt']">
- <xsl:text>]</xsl:text>
- </xsl:if>
- <xsl:text>)</xsl:text>
- </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-
-<!-- Remove whitespace before and after the contents of
- programlisting and screen tags used for PHP code and
- output examples
-
- Thanks to Peter Kullman for the initial version of this code
--->
-<xsl:template match="screen/text()|programlisting/text()">
- <xsl:variable name="before" select="preceding-sibling::node()"/>
- <xsl:variable name="after" select="following-sibling::node()"/>
-
- <xsl:variable name="conts" select="."/>
-
- <xsl:variable name="contsl">
- <xsl:choose>
- <xsl:when test="count($before) = 0">
- <xsl:call-template name="remove-ws-left">
- <xsl:with-param name="astr" select="$conts"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$conts"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
-
- <xsl:variable name="contslr">
- <xsl:choose>
- <xsl:when test="count($after) = 0">
- <xsl:call-template name="remove-ws-right">
- <xsl:with-param name="astr" select="$contsl"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$contsl"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
-
- <xsl:value-of select="$contslr"/>
-
-</xsl:template>
-
-<!-- Remove whitespace from the left of a string -->
-<xsl:template name="remove-ws-left">
- <xsl:param name="astr"/>
-
- <xsl:choose>
- <xsl:when test="starts-with($astr,'
') or
- starts-with($astr,'
') or
- starts-with($astr,' ') or
- starts-with($astr,'	')">
- <xsl:call-template name="remove-ws-left">
- <xsl:with-param name="astr" select="substring($astr, 2)"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$astr"/>
- </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-<!-- Remove whitespace from the right of a string -->
-<xsl:template name="remove-ws-right">
- <xsl:param name="astr"/>
-
- <xsl:variable name="last-char">
- <xsl:value-of select="substring($astr, string-length($astr), 1)"/>
- </xsl:variable>
-
- <xsl:choose>
- <xsl:when test="($last-char = '
') or
- ($last-char = '
') or
- ($last-char = ' ') or
- ($last-char = '	')">
- <xsl:call-template name="remove-ws-right">
- <xsl:with-param name="astr"
- select="substring($astr, 1, string-length($astr) - 1)"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$astr"/>
- </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-
-
-<!-- *************** FOR TRANSLATORS LIST **************** -->
-<xsl:template match="collab" mode="titlepage.mode">
- <xsl:choose>
- <xsl:when test="position()=last()">
- <xsl:apply-templates/>
- </xsl:when>
- <xsl:when test="position() > 1">
- <xsl:apply-templates/><xsl:text>, </xsl:text>
- </xsl:when>
- <xsl:otherwise></xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-<xsl:template match="collabname">
- <xsl:apply-templates/>
-</xsl:template>
-
-</xsl:stylesheet>
+ </xsl:for-each>
+ <xsl:if test="self::methodparam/attribute::choice[.='opt']">
+ <xsl:text>]</xsl:text>
+ </xsl:if>
+ <xsl:text>)</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+
+
+<!-- *************** TUNE PROGRAMLISTING DISPLAY **************** -->
+<!-- This is the same as in DocBook XSL verbatim.xsl, except
+ that we preserve the role in programlisting and the like -->
+<xsl:template match="programlisting|screen|synopsis">
+ <xsl:param name="suppress-numbers" select="'0'"/>
+ <xsl:variable name="id">
+ <xsl:call-template name="object.id"/>
+ </xsl:variable>
+
+ <xsl:call-template name="anchor"/>
+
+ <xsl:variable name="preclass">
+ <xsl:choose>
+ <xsl:when test="./@role">
+ <xsl:value-of select="./@role"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="name(.)"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:variable name="content">
+ <xsl:choose>
+ <xsl:when test="$suppress-numbers = '0'
+ and @linenumbering = 'numbered'
+ and $use.extensions != '0'
+ and $linenumbering.extension != '0'">
+ <xsl:variable name="rtf">
+ <xsl:apply-templates/>
+ </xsl:variable>
+ <pre class="{$preclass}">
+ <xsl:call-template name="number.rtf.lines">
+ <xsl:with-param name="rtf" select="$rtf"/>
+ </xsl:call-template>
+ </pre>
+ </xsl:when>
+ <xsl:otherwise>
+ <pre class="{$preclass}">
+ <xsl:apply-templates/>
+ </pre>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:choose>
+ <xsl:when test="$shade.verbatim != 0">
+ <table xsl:use-attribute-sets="shade.verbatim.style">
+ <tr>
+ <td>
+ <xsl:copy-of select="$content"/>
+ </td>
+ </tr>
+ </table>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:copy-of select="$content"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+
+<!-- Strip newlines before and after the contents of program listing and
+ and screen tags used for PHP code and output examples preserve
+ identation of the first line.
+
+ Initial version by techtonik =p
+ Thanks to Peter Kullman for an idea
+-->
+<xsl:template match="screen/text()|programlisting/text()">
+ <xsl:variable name="before" select="count(preceding-sibling::*)"/>
+ <xsl:variable name="after" select="count(following-sibling::*)"/>
+
+ <xsl:choose>
+ <xsl:when test="$before = 0 and $after = 0">
+ <xsl:call-template name="trim_newlines"/>
+ </xsl:when>
+ <xsl:when test="$before = 0">
+ <xsl:call-template name="trim_newlines">
+ <xsl:with-param name="lttrim" select="true()"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="$after = 0">
+ <xsl:call-template name="trim_newlines">
+ <xsl:with-param name="rttrim" select="true()"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="."/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="trim_newlines">
+ <xsl:param name="string" select="."/>
+ <xsl:param name="lttrim" select="false()"/>
+ <xsl:param name="rttrim" select="false()"/> <!-- looking for endstring -->
+
+ <xsl:variable name="nl" select="'
'" />
+
+ <xsl:choose>
+ <xsl:when test="normalize-space($string) and contains($string,$nl)"><!-- prevent
endless cycle on empty blocks -->
+ <xsl:variable name="beforenl" select="substring-before($string,$nl)" />
+ <xsl:variable name="afternl" select="substring-after($string,$nl)" />
+ <xsl:variable name="nextnl"
select="normalize-space(substring-before($afternl,$nl))" />
+ <xsl:choose>
+ <xsl:when test="not($rttrim) and string-length(normalize-space($beforenl)) =
0">
+ <xsl:call-template name="trim_newlines">
+ <xsl:with-param name="string" select="$afternl" />
+ <xsl:with-param name="lttrim" select="$lttrim" />
+ <xsl:with-param name="rttrim" select="$rttrim or $nextnl" />
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:copy-of select="concat($beforenl,$nl)"/>
+ <xsl:if test="$lttrim">
+ <xsl:copy-of select="$afternl"/>
+ </xsl:if>
+ <xsl:if test="not($lttrim)">
+ <xsl:call-template name="trim_newlines">
+ <xsl:with-param name="string" select="$afternl" />
+ <xsl:with-param name="rttrim" select="true()" />
+ </xsl:call-template>
+ </xsl:if>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:if test="normalize-space($string)">
+ <xsl:copy-of select="$string"/>
+ </xsl:if>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+
+
+<!-- *************** FOR TRANSLATORS LIST **************** -->
+<xsl:template match="collab" mode="titlepage.mode">
+ <xsl:choose>
+ <xsl:when test="position()=last()">
+ <xsl:apply-templates/>
+ </xsl:when>
+ <xsl:when test="position() > 1">
+ <xsl:apply-templates/><xsl:text>, </xsl:text>
+ </xsl:when>
+ <xsl:otherwise></xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template match="collabname">
+ <xsl:apply-templates/>
+</xsl:template>
+
+</xsl:stylesheet>