Ignore:
Timestamp:
Jul 6, 2008, 6:57:34 AM (12 years ago)
Author:
julian.reschke@…
Message:

Update to latest version of rfc2629.xslt, and take advantage of it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rfc2629xslt/rfc2629.xslt

    r246 r272  
    305305  match="xref[@x:rel]"
    306306    use="concat(@target,'..',@x:rel)" />
     307
     308<xsl:key name="anchor-item"
     309  match="//*[@anchor]"
     310    use="@anchor"/>
     311
     312<xsl:key name="xref-item"
     313  match="//xref"
     314    use="@target"/>
     315
     316<xsl:key name="extref-item"
     317  match="//x:ref"
     318    use="."/>
    307319
    308320<!-- prefix for automatically generated anchors -->
     
    361373<xsl:variable name="has-index" select="//iref or (//xref and $xml2rfc-ext-include-references-in-index='yes')" />
    362374         
     375<!-- does the document contain edits? -->
     376<xsl:variable name="has-edits" select="//ed:ins | //ed:del | //ed:replace" />
     377
    363378<!-- Templates for the various elements of rfc2629.dtd -->
    364379             
     
    603618        </span>
    604619      </xsl:if>
    605       <xsl:if test="address/email">
     620      <xsl:for-each select="address/email">
     621        <xsl:variable name="email">
     622          <xsl:call-template name="extract-email"/>
     623        </xsl:variable>
     624       
    606625        <span class="vcardline">
    607         <xsl:text>EMail: </xsl:text>
    608         <a>
    609           <xsl:if test="$xml2rfc-linkmailto!='no'">
    610             <xsl:attribute name="href">mailto:<xsl:value-of select="address/email" /></xsl:attribute>
    611           </xsl:if>
    612           <span class="email"><xsl:value-of select="address/email" /></span>
    613         </a>
     626          <xsl:text>EMail: </xsl:text>
     627          <a>
     628            <xsl:if test="$xml2rfc-linkmailto!='no'">
     629              <xsl:attribute name="href">mailto:<xsl:value-of select="$email" /></xsl:attribute>
     630            </xsl:if>
     631            <span class="email"><xsl:value-of select="$email" /></span>
     632          </a>
    614633        </span>
    615       </xsl:if>
     634      </xsl:for-each>
    616635      <xsl:if test="address/uri">
    617636        <span class="vcardline">
     
    655674    <!-- emit it -->
    656675    <xsl:choose>
    657       <xsl:when test="function-available('msxsl:node-set')">
    658         <xsl:apply-templates select="msxsl:node-set($copyright)" />
    659       </xsl:when>
    660676      <xsl:when test="function-available('exslt:node-set')">
    661677        <xsl:apply-templates select="exslt:node-set($copyright)" />
     
    719735    <table summary="header information" class="header" border="0" cellpadding="1" cellspacing="1">
    720736      <xsl:choose>
    721         <xsl:when test="function-available('msxsl:node-set')">
    722           <xsl:call-template name="emitheader">
    723             <xsl:with-param name="lc" select="msxsl:node-set($leftColumn)" />   
    724             <xsl:with-param name="rc" select="msxsl:node-set($rightColumn)" />   
    725           </xsl:call-template>
    726         </xsl:when>   
    727737        <xsl:when test="function-available('exslt:node-set')">
    728738          <xsl:call-template name="emitheader">
     
    769779    <!-- emit it -->
    770780    <xsl:choose>
    771       <xsl:when test="function-available('msxsl:node-set')">
    772         <xsl:apply-templates select="msxsl:node-set($preamble)" />
    773       </xsl:when>
    774781      <xsl:when test="function-available('exslt:node-set')">
    775782        <xsl:apply-templates select="exslt:node-set($preamble)" />
     
    11161123  <!-- check for reference to reference -->
    11171124  <xsl:variable name="anchor" select="@anchor"/>
    1118   <xsl:if test="not(ancestor::ed:del) and not(//xref[@target=$anchor])">
    1119     <xsl:message>WARNING: unused reference '<xsl:value-of select="@anchor"/>'<xsl:call-template name="lineno"/></xsl:message>
     1125  <xsl:if test="not(ancestor::ed:del) and not(key('xref-item',$anchor))">
     1126    <xsl:call-template name="warning">
     1127      <xsl:with-param name="inline" select="'no'"/>
     1128      <xsl:with-param name="msg">unused reference '<xsl:value-of select="@anchor"/>'</xsl:with-param>
     1129    </xsl:call-template>
    11201130  </xsl:if>
    11211131
     
    13541364  <!-- conformance checks -->
    13551365  <xsl:if test="$xml2rfc-symrefs!='no' and $xml2rfc-symrefs!='yes' and //reference">
    1356     <xsl:message>WARNING: symrefs PI not specified; default has changed from 'no' to 'yes'.</xsl:message>
     1366    <xsl:call-template name="warning">
     1367      <xsl:with-param name="inline" select="'no'"/>
     1368      <xsl:with-param name="msg">symrefs PI not specified; default has changed from 'no' to 'yes'.</xsl:with-param>
     1369    </xsl:call-template>
    13571370  </xsl:if>
    13581371 
     
    17051718
    17061719  <xsl:variable name="target" select="@target" />
    1707   <xsl:variable name="node" select="$src//*[@anchor=$target]" />
     1720  <xsl:variable name="node" select="key('anchor-item',$target)" />
    17081721  <xsl:variable name="anchor"><xsl:value-of select="$anchor-prefix"/>.xref.<xsl:value-of select="@target"/>.<xsl:number level="any" count="xref[@target=$target]"/></xsl:variable>
    17091722
     
    17741787</xsl:template>
    17751788               
     1789<xsl:key name="iref-xanch" match="iref[@x:for-anchor]" use="@x:for-anchor"/>           
     1790               
    17761791<xsl:template match="xref[not(node())]">
    17771792
     
    17791794  <xsl:variable name="target" select="@target" />
    17801795  <xsl:variable name="anchor"><xsl:value-of select="$anchor-prefix"/>.xref.<xsl:value-of select="@target"/>.<xsl:number level="any" count="xref[@target=$target]"/></xsl:variable>
    1781   <xsl:variable name="node" select="$src//*[@anchor=$target]" />
     1796  <xsl:variable name="node" select="key('anchor-item',$target)" />
    17821797  <xsl:if test="count($node)=0 and not(ancestor::ed:del)">
    17831798    <xsl:call-template name="error">
     
    17921807      <a href="#{@target}">
    17931808        <!-- insert id when a backlink to this xref is needed in the index -->
    1794         <xsl:if test="//iref[@x:for-anchor=$target] | //iref[@x:for-anchor='' and ../@anchor=$target]">
     1809        <xsl:if test="key('iref-xanch',$target) | key('iref-xanch','')[../@anchor=$target]">
    17951810          <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
    17961811        </xsl:if>
     
    27972812  background-color: yellow;
    27982813}
    2799 <xsl:if test="//ed:del|//ed:replace|//ed:ins">del {
     2814<xsl:if test="$has-edits">del {
    28002815  color: red;
    28012816  text-decoration: line-through;
     
    31403155                        <xsl:text>&#160;&#160;</xsl:text>
    31413156                       
    3142                         <xsl:variable name="rs" select="//xref[@target=current()/@anchor] | . | //reference[@anchor=concat('deleted-',current()/@anchor)]"/>
     3157                        <xsl:variable name="rs" select="key('xref-item',current()/@anchor) | . | key('anchor-item',concat('deleted-',current()/@anchor))"/>
     3158                       
    31433159                        <xsl:for-each select="$rs">
    31443160                          <xsl:call-template name="insertSingleXref" />
     
    31553171                                <li class="indline1">
    31563172                                  <em>
    3157                                     <xsl:text>Section </xsl:text>
     3173                                    <xsl:choose>
     3174                                      <xsl:when test="translate(substring(@x:sec,1,1),$ucase,'')=''">
     3175                                        <xsl:text>Appendix </xsl:text>
     3176                                      </xsl:when>
     3177                                      <xsl:otherwise>
     3178                                        <xsl:text>Section </xsl:text>
     3179                                      </xsl:otherwise>
     3180                                    </xsl:choose>
    31583181                                    <xsl:value-of select="@x:sec"/>
    31593182                                  </em>
     
    31783201                                  <li class="indline1">
    31793202                                    <em>
    3180                                       <xsl:text>Section </xsl:text>
    3181                                       <xsl:for-each select="$doc//*[@anchor=substring-after(current()/@x:rel,'#')]">
    3182                                         <xsl:call-template name="get-section-number"/>
    3183                                       </xsl:for-each>
     3203                                      <xsl:variable name="sec">
     3204                                        <xsl:for-each select="$doc//*[@anchor=substring-after(current()/@x:rel,'#')]">
     3205                                          <xsl:call-template name="get-section-number"/>
     3206                                        </xsl:for-each>
     3207                                      </xsl:variable>
     3208                                      <xsl:choose>
     3209                                        <xsl:when test="translate(substring($sec,1,1),$ucase,'')=''">
     3210                                          <xsl:text>Appendix </xsl:text>
     3211                                        </xsl:when>
     3212                                        <xsl:otherwise>
     3213                                          <xsl:text>Section </xsl:text>
     3214                                        </xsl:otherwise>
     3215                                      </xsl:choose>
     3216                                      <xsl:value-of select="$sec"/>
    31843217                                    </em>
    31853218                                    <xsl:text>&#160;&#160;</xsl:text>
     
    32003233                    <xsl:if test="generate-id(.) = generate-id(key('index-item',concat(@item,@anchor)))">
    32013234                      <xsl:variable name="item" select="@item"/>
    3202                       <xsl:variable name="in-artwork" select="count(//iref[@item=$item and @primary='true' and ancestor::artwork])!=0"/>
     3235                      <xsl:variable name="in-artwork" select="key('index-item',$item)[@primary='true' and ancestor::artwork]"/>
    32033236                         
    32043237                      <li class="indline1">
     
    32143247                       
    32153248                        <xsl:variable name="irefs3" select="key('index-item',@item)[not(@subitem) or @subitem='']"/>
    3216                         <xsl:variable name="xrefs3" select="//xref[@target=$irefs3[@x:for-anchor='']/../@anchor or @target=$irefs3/@x:for-anchor]"/>
    3217                         <xsl:variable name="extrefs3" select="//x:ref[.=$irefs3[@x:for-anchor='']/../@anchor or .=$irefs3/@x:for-anchor]"/>
     3249                        <xsl:variable name="xrefs3" select="key('xref-item',$irefs3[@x:for-anchor='']/../@anchor) | key('xref-item',$irefs3/@x:for-anchor)"/>
     3250                        <xsl:variable name="extrefs3" select="key('extref-item',$irefs3[@x:for-anchor='']/../@anchor) | key('extref-item',$irefs3/@x:for-anchor)"/>
    32183251
    32193252                        <xsl:for-each select="$irefs3|$xrefs3|$extrefs3">
     
    32313264                 
    32323265                                <xsl:variable name="itemsubitem" select="concat(@item,'..',@subitem)"/>
    3233                                 <xsl:variable name="in-artwork2" select="count(//iref[concat(@item,'..',@subitem)=$itemsubitem and @primary='true' and ancestor::artwork])!=0"/>
     3266                                <xsl:variable name="in-artwork2" select="key('index-item-subitem',concat(@item,'..',@subitem))[@primary='true' and ancestor::artwork]" />
    32343267                 
    32353268                                <li class="indline1">
     
    32463279                                   
    32473280                                  <xsl:variable name="irefs4" select="key('index-item-subitem',concat(@item,'..',@subitem))"/>
    3248                                   <xsl:variable name="xrefs4" select="//xref[@target=$irefs4[@x:for-anchor='']/../@anchor or @target=$irefs4/@x:for-anchor]"/>
    3249                                   <xsl:variable name="extrefs4" select="//x:ref[.=$irefs4[@x:for-anchor='']/../@anchor or .=$irefs4/@x:for-anchor]"/>
     3281                                  <xsl:variable name="xrefs4" select="key('xref-item',$irefs4[@x:for-anchor='']/../@anchor) | key('xref-item',$irefs4/@x:for-anchor)"/>
     3282                                  <xsl:variable name="extrefs4" select="key('extref-item',$irefs4[@x:for-anchor='']/../@anchor) | key('extref-item',$irefs4/@x:for-anchor)"/>
    32503283
    32513284                                  <xsl:for-each select="$irefs4|$xrefs4|$extrefs4">
     
    38853918
    38863919<!-- internal ref support -->
     3920<xsl:key name="anchor-item-alias" match="//*[@anchor and (x:anchor-alias/@value or ed:replace/ed:ins/x:anchor-alias)]" use="x:anchor-alias/@value | ed:replace/ed:ins/x:anchor-alias/@value"/>
     3921
    38873922<xsl:template match="x:ref">
    38883923  <xsl:variable name="val" select="."/>
    3889   <xsl:variable name="target" select="//*[(@anchor and x:anchor-alias/@value=$val) or (@anchor and ed:replace/ed:ins/x:anchor-alias/@value=$val) or (@anchor=$val)]"/>
     3924<!--  <xsl:variable name="target" select="//*[(@anchor and x:anchor-alias/@value=$val) or (@anchor and ed:replace/ed:ins/x:anchor-alias/@value=$val) or (@anchor=$val)]"/> -->
     3925  <xsl:variable name="target" select="key('anchor-item',$val) | key('anchor-item-alias',$val)"/>
    38903926  <xsl:variable name="irefs" select="//iref[@x:for-anchor=$val]"/>
    38913927  <xsl:choose>
     
    39003936    </xsl:when>
    39013937    <xsl:otherwise>
    3902       <xsl:message>WARNING: internal link target for '<xsl:value-of select="."/>' does not exist.<xsl:call-template name="lineno"/></xsl:message>
     3938      <xsl:call-template name="warning">
     3939        <xsl:with-param name="inline" select="'no'"/>
     3940        <xsl:with-param name="msg">internal link target for '<xsl:value-of select="."/>' does not exist.</xsl:with-param>
     3941      </xsl:call-template>
    39033942      <xsl:value-of select="."/>
    39043943    </xsl:otherwise>
     
    40064045<xsl:template match="x:span">
    40074046  <xsl:apply-templates/>
     4047</xsl:template>
     4048
     4049<!-- ABNF support -->
     4050<xsl:template name="to-abnf-char-sequence">
     4051  <xsl:param name="chars"/>
     4052 
     4053  <xsl:variable name="c" select="substring($chars,1,1)"/>
     4054  <xsl:variable name="r" select="substring($chars,2)"/>
     4055   
     4056  <xsl:choose>
     4057    <xsl:when test="$c='A'">41</xsl:when>
     4058    <xsl:when test="$c='B'">42</xsl:when>
     4059    <xsl:when test="$c='C'">43</xsl:when>
     4060    <xsl:when test="$c='D'">44</xsl:when>
     4061    <xsl:when test="$c='E'">45</xsl:when>
     4062    <xsl:when test="$c='F'">46</xsl:when>
     4063    <xsl:when test="$c='G'">47</xsl:when>
     4064    <xsl:when test="$c='H'">48</xsl:when>
     4065    <xsl:when test="$c='I'">49</xsl:when>
     4066    <xsl:when test="$c='J'">4A</xsl:when>
     4067    <xsl:when test="$c='K'">4B</xsl:when>
     4068    <xsl:when test="$c='L'">4C</xsl:when>
     4069    <xsl:when test="$c='M'">4D</xsl:when>
     4070    <xsl:when test="$c='N'">4E</xsl:when>
     4071    <xsl:when test="$c='O'">4F</xsl:when>
     4072    <xsl:when test="$c='P'">50</xsl:when>
     4073    <xsl:when test="$c='Q'">51</xsl:when>
     4074    <xsl:when test="$c='R'">52</xsl:when>
     4075    <xsl:when test="$c='S'">53</xsl:when>
     4076    <xsl:when test="$c='T'">54</xsl:when>
     4077    <xsl:when test="$c='U'">55</xsl:when>
     4078    <xsl:when test="$c='V'">56</xsl:when>
     4079    <xsl:when test="$c='W'">57</xsl:when>
     4080    <xsl:when test="$c='X'">58</xsl:when>
     4081    <xsl:when test="$c='Y'">59</xsl:when>
     4082    <xsl:when test="$c='Z'">5A</xsl:when>
     4083    <xsl:when test="$c='a'">61</xsl:when>
     4084    <xsl:when test="$c='b'">62</xsl:when>
     4085    <xsl:when test="$c='c'">63</xsl:when>
     4086    <xsl:when test="$c='d'">64</xsl:when>
     4087    <xsl:when test="$c='e'">65</xsl:when>
     4088    <xsl:when test="$c='f'">66</xsl:when>
     4089    <xsl:when test="$c='g'">67</xsl:when>
     4090    <xsl:when test="$c='h'">68</xsl:when>
     4091    <xsl:when test="$c='i'">69</xsl:when>
     4092    <xsl:when test="$c='j'">6A</xsl:when>
     4093    <xsl:when test="$c='k'">6B</xsl:when>
     4094    <xsl:when test="$c='l'">6C</xsl:when>
     4095    <xsl:when test="$c='m'">6D</xsl:when>
     4096    <xsl:when test="$c='n'">6E</xsl:when>
     4097    <xsl:when test="$c='o'">6F</xsl:when>
     4098    <xsl:when test="$c='p'">70</xsl:when>
     4099    <xsl:when test="$c='q'">71</xsl:when>
     4100    <xsl:when test="$c='r'">72</xsl:when>
     4101    <xsl:when test="$c='s'">73</xsl:when>
     4102    <xsl:when test="$c='t'">74</xsl:when>
     4103    <xsl:when test="$c='u'">75</xsl:when>
     4104    <xsl:when test="$c='v'">76</xsl:when>
     4105    <xsl:when test="$c='w'">77</xsl:when>
     4106    <xsl:when test="$c='x'">78</xsl:when>
     4107    <xsl:when test="$c='y'">79</xsl:when>
     4108    <xsl:when test="$c='z'">7A</xsl:when>
     4109    <xsl:otherwise>
     4110      <xsl:text>??</xsl:text>
     4111      <xsl:call-template name="error">
     4112        <xsl:with-param name="msg" select="concat('unexpected character in ABNF char sequence: ',substring($chars,1,1))" />
     4113      </xsl:call-template>
     4114    </xsl:otherwise>
     4115  </xsl:choose>
     4116
     4117  <xsl:if test="$r!=''">
     4118    <xsl:text>.</xsl:text>
     4119    <xsl:call-template name="to-abnf-char-sequence">
     4120      <xsl:with-param name="chars" select="$r"/>
     4121    </xsl:call-template>
     4122  </xsl:if>
     4123 
     4124</xsl:template>
     4125
     4126<xsl:template match="x:abnf-char-sequence">
     4127  <xsl:choose>
     4128    <xsl:when test="substring(.,1,1) != '&quot;' or substring(.,string-length(.),1) != '&quot;'">
     4129      <xsl:call-template name="error">
     4130        <xsl:with-param name="msg" select="'contents of x:abnf-char-sequence needs to be quoted.'" />
     4131      </xsl:call-template>
     4132    </xsl:when>
     4133    <xsl:otherwise>
     4134      <xsl:text>%x</xsl:text>
     4135      <xsl:call-template name="to-abnf-char-sequence">
     4136        <xsl:with-param name="chars" select="substring(.,2,string-length(.)-2)"/>
     4137      </xsl:call-template>
     4138    </xsl:otherwise>
     4139  </xsl:choose>
    40084140</xsl:template>
    40094141
     
    46974829      </dt>
    46984830      <dd>
    4699         <xsl:value-of select="."/>
     4831        <xsl:apply-templates select="node()"/>
    47004832        <xsl:if test="@source"> --<xsl:value-of select="@source"/></xsl:if>
    47014833      </dd>
     
    48034935    <xsl:text>http://greenbytes.de/tech/webdav/rfc2629.xslt, </xsl:text>
    48044936    <!-- when RCS keyword substitution in place, add version info -->
    4805     <xsl:if test="contains('$Revision: 1.367 $',':')">
    4806       <xsl:value-of select="concat('Revision ',normalize-space(translate(substring-after('$Revision: 1.367 $', 'Revision: '),'$','')),', ')" />
     4937    <xsl:if test="contains('$Revision: 1.379 $',':')">
     4938      <xsl:value-of select="concat('Revision ',normalize-space(translate(substring-after('$Revision: 1.379 $', 'Revision: '),'$','')),', ')" />
    48074939    </xsl:if>
    4808     <xsl:if test="contains('$Date: 2008-05-19 13:00:19 $',':')">
    4809       <xsl:value-of select="concat(normalize-space(translate(substring-after('$Date: 2008-05-19 13:00:19 $', 'Date: '),'$','')),', ')" />
     4940    <xsl:if test="contains('$Date: 2008-07-06 13:38:32 $',':')">
     4941      <xsl:value-of select="concat(normalize-space(translate(substring-after('$Date: 2008-07-06 13:38:32 $', 'Date: '),'$','')),', ')" />
    48104942    </xsl:if>
    48114943    <xsl:value-of select="concat('XSLT vendor: ',system-property('xsl:vendor'),' ',system-property('xsl:vendor-url'))" />
     
    48374969
    48384970<xsl:template name="get-section-number">
    4839   <xsl:variable name="hasEdits" select="count(//ed:del|//ed:ins)!=0" />
    48404971  <xsl:variable name="anchor" select="@anchor"/>
    48414972  <xsl:choose>
     
    48434974      <xsl:value-of select="@x:fixed-section-number"/>
    48444975    </xsl:when>
    4845     <xsl:when test="$hasEdits or ancestor::*/@x:fixed-section-number">
     4976    <xsl:when test="$has-edits or ancestor::*/@x:fixed-section-number">
    48464977      <xsl:call-template name="sectionnumberAndEdits" />
    48474978    </xsl:when>
     
    48895020
    48905021<xsl:template name="get-section-type">
    4891   <xsl:param name="prec" />
     5022  <xsl:param name="prec" /> <!-- TODO: check this, it's unused -->
    48925023  <xsl:choose>
    48935024    <xsl:when test="ancestor::back">Appendix</xsl:when>
     
    49345065    </xsl:otherwise>
    49355066  </xsl:choose>
     5067</xsl:template>
     5068
     5069<!-- checking for email element -->
     5070<xsl:template name="extract-email">
     5071  <xsl:variable name="email" select="normalize-space(.)"/>
     5072  <xsl:if test="string-length(.) != string-length($email) or contains($email,' ')">
     5073    <xsl:call-template name="warning">
     5074      <xsl:with-param name="inline" select="'no'"/>
     5075      <xsl:with-param name="msg">excessive whitespace in email address: '<xsl:value-of select="."/>'</xsl:with-param>
     5076    </xsl:call-template>
     5077  </xsl:if>
     5078 
     5079  <xsl:variable name="email2">
     5080    <xsl:choose>
     5081      <xsl:when test="starts-with($email,'mailto:')">
     5082        <xsl:call-template name="warning">
     5083          <xsl:with-param name="inline" select="'no'"/>
     5084          <xsl:with-param name="msg">email should not include URI scheme: '<xsl:value-of select="."/>'</xsl:with-param>
     5085        </xsl:call-template>
     5086        <xsl:value-of select="substring($email, 1 + string-length('mailto:'))"/>
     5087      </xsl:when>
     5088      <xsl:otherwise>
     5089        <xsl:value-of select="$email"/>
     5090      </xsl:otherwise>
     5091    </xsl:choose>
     5092  </xsl:variable>
     5093 
     5094  <xsl:value-of select="$email2"/>
    49365095</xsl:template>
    49375096
     
    49785137  </xsl:if>
    49795138</xsl:template>
     5139
     5140<!-- define exslt:node-set for msxml -->       
     5141<msxsl:script language="JScript" implements-prefix="exslt">
     5142  this['node-set'] = function (x) {
     5143    return x;
     5144  }
     5145</msxsl:script>
    49805146
    49815147<!-- date handling -->
Note: See TracChangeset for help on using the changeset viewer.