cvs: phpdoc /xsl common.xsl
| From: | Gabor Hojtsy | Date: | Sun, 27 Apr 2003 17:06:10 +0000 |
| Subject: | cvs: phpdoc /xsl common.xsl | ||
| Groups: | php.doc | ||
| Request: | Send a blank email to phpdoc+get-969352910@lists.php.net to get a copy of this message | ||
goba Sun Apr 27 13:06:10 2003 EDT
Modified files:
/phpdoc/xsl common.xsl
Log:
Adding code to trim() space in screen and
programlisting tags, with many thanks to Peter
Kullman
Index: phpdoc/xsl/common.xsl
diff -u phpdoc/xsl/common.xsl:1.7 phpdoc/xsl/common.xsl:1.8
--- phpdoc/xsl/common.xsl:1.7 Sun Mar 9 10:01:13 2003
+++ phpdoc/xsl/common.xsl Sun Apr 27 13:06:09 2003
@@ -101,5 +101,89 @@
<xsl:apply-templates/>
</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>
</xsl:stylesheet>