1<?xml version="1.0" encoding="UTF-8"?> 2<xsl:stylesheet version="1.0" 3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 4 xmlns:tex="urn:org:tug:texhyphen" 5 xmlns:lang="urn:org:tug:texhyphen:languagedata" 6 exclude-result-prefixes="tex lang"> 7 8 <xsl:output doctype-system="hyphenation.dtd" indent="yes"/> 9 10 <xsl:param name="comment-length" select="72"/> 11 <xsl:param name="tex-code"/> 12 <xsl:param name="hyphen-min-before-default" select="2"/> 13 <xsl:param name="hyphen-min-after-default" select="3"/> 14 15 <xsl:template match="/tex:tex"> 16 <hyphenation-info> 17 <xsl:choose> 18 <xsl:when test="tex:hyphenation"> 19 <!-- (comment*), (patterns), (comment*, hyphenation, comment*) => (comment*), hyphen-min, (comment*, exceptions, comment*), (patterns) --> 20 <xsl:variable name="set1" select="node()[following-sibling::tex:patterns]"/> 21 <xsl:variable name="set2" select="tex:patterns"/> 22 <xsl:variable name="set3" select="node()[preceding-sibling::tex:patterns]"/> 23 <xsl:apply-templates select="$set1"/> 24 <xsl:call-template name="hyphen-min"/> 25 <xsl:apply-templates select="$set3"/> 26 <xsl:apply-templates select="$set2"/> 27 </xsl:when> 28 <xsl:otherwise> 29 <!-- (comment*), (patterns, comment*) => (comment*), hyphen-min, (patterns, comment*) --> 30 <xsl:variable name="set1" select="node()[following-sibling::tex:patterns]"/> 31 <xsl:variable name="set2" select="node()[preceding-sibling::tex:patterns or self::tex:patterns]"/> 32 <xsl:apply-templates select="$set1"/> 33 <xsl:call-template name="hyphen-min"/> 34 <xsl:apply-templates select="$set2"/> 35 </xsl:otherwise> 36 </xsl:choose> 37 </hyphenation-info> 38 </xsl:template> 39 40 <xsl:template match="tex:patterns"> 41 <patterns> 42 <xsl:apply-templates /> 43 </patterns> 44 </xsl:template> 45 46 <xsl:template match="tex:patterns" mode="call-hyphen-min"> 47 <xsl:call-template name="hyphen-min"/> 48 <patterns> 49 <xsl:apply-templates /> 50 </patterns> 51 </xsl:template> 52 53 <xsl:template name="hyphen-min"> 54 <xsl:variable name="hyphen-min" 55 select="document('languages.xml')/lang:languages/lang:language[@code=$tex-code]/lang:hyphen-min" /> 56 <xsl:if test="count($hyphen-min)"> 57 <hyphen-min before="{$hyphen-min/@before}" after="{$hyphen-min/@after}" /> 58 </xsl:if> 59 </xsl:template> 60 61 <xsl:template match="tex:message"/> 62 63 <xsl:template match="tex:hyphenation"> 64 <exceptions> 65 <xsl:apply-templates /> 66 </exceptions> 67 </xsl:template> 68 69 <!-- Comments in TeX contain the trailing new line. --> 70 <!-- Here we keep the trailing new line if the comment is immediately --> 71 <!-- preceded or followed by a text node. --> 72 <!-- Otherwise we strip the new line and pad the comment --> 73 <!-- to the parameter comment-length. --> 74 <!-- The XSLT engine uses the same criteria to decide if the comment --> 75 <!-- should start on a new line or not. --> 76 <!-- This is not quite correct, because we risk adding spaces to --> 77 <!-- elements with mixed content. --> 78 <!-- The following test would be more appropriate: --> 79 <!-- test="preceding-sibling::text() or following-sibling::text()". --> 80 <xsl:template match="comment()"> 81 <xsl:choose> 82 <xsl:when 83 test="preceding-sibling::node()[1][self::text()] 84 or following-sibling::node()[1][self::text()]"> 85 <xsl:comment> 86 <xsl:value-of select="." /> 87 </xsl:comment> 88 </xsl:when> 89 <xsl:otherwise> 90 <xsl:variable name="length" select="string-length(.)" /> 91 <xsl:comment> 92 <xsl:value-of select="substring(.,1,$length - 1)" /> 93 <xsl:text> </xsl:text> 94 <xsl:call-template name="make-spaces"> 95 <xsl:with-param name="length" 96 select="$comment-length - ($length - 1)" /> 97 </xsl:call-template> 98 </xsl:comment> 99 </xsl:otherwise> 100 </xsl:choose> 101 </xsl:template> 102 103 <xsl:template name="make-spaces"> 104 <xsl:param name="length" select="0" /> 105 <xsl:choose> 106 <xsl:when test="$length >= 10"> 107 <xsl:text> </xsl:text> 108 <xsl:call-template name="make-spaces"> 109 <xsl:with-param name="length" select="$length - 10" /> 110 </xsl:call-template> 111 </xsl:when> 112 <xsl:when test="$length >= 5"> 113 <xsl:text> </xsl:text> 114 <xsl:call-template name="make-spaces"> 115 <xsl:with-param name="length" select="$length - 5" /> 116 </xsl:call-template> 117 </xsl:when> 118 <xsl:when test="$length >= 1"> 119 <xsl:text> </xsl:text> 120 <xsl:call-template name="make-spaces"> 121 <xsl:with-param name="length" select="$length - 1" /> 122 </xsl:call-template> 123 </xsl:when> 124 </xsl:choose> 125 <xsl:text></xsl:text> 126 </xsl:template> 127 128</xsl:stylesheet>