Ignore:
Timestamp:
Jul 6, 2008, 6:57:34 AM (11 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/rfc2629toXHTML.xslt

    r246 r272  
    161161<xsl:key name="index-xref-by-anchor" match="xref[@x:rel]" use="concat(@target,'..',@x:rel)"/>
    162162
     163<xsl:key name="anchor-item" match="//*[@anchor]" use="@anchor"/>
     164
     165<xsl:key name="xref-item" match="//xref" use="@target"/>
     166
     167<xsl:key name="extref-item" match="//x:ref" use="."/>
     168
    163169<!-- prefix for automatically generated anchors -->
    164170<xsl:variable name="anchor-prefix" select="'rfc'"/>
     
    181187<xsl:variable name="has-index" select="//iref or (//xref and $xml2rfc-ext-include-references-in-index='yes')"/>
    182188         
     189<!-- does the document contain edits? -->
     190<xsl:variable name="has-edits" select="//ed:ins | //ed:del | //ed:replace"/>
     191
    183192<!-- Templates for the various elements of rfc2629.dtd -->
    184193             
     
    423432        </span>
    424433      </xsl:if>
    425       <xsl:if test="address/email">
     434      <xsl:for-each select="address/email">
     435        <xsl:variable name="email">
     436          <xsl:call-template name="extract-email"/>
     437        </xsl:variable>
     438       
    426439        <span class="vcardline">
    427         <xsl:text>EMail: </xsl:text>
    428         <a>
    429           <xsl:if test="$xml2rfc-linkmailto!='no'">
    430             <xsl:attribute name="href">mailto:<xsl:value-of select="address/email"/></xsl:attribute>
    431           </xsl:if>
    432           <span class="email"><xsl:value-of select="address/email"/></span>
    433         </a>
     440          <xsl:text>EMail: </xsl:text>
     441          <a>
     442            <xsl:if test="$xml2rfc-linkmailto!='no'">
     443              <xsl:attribute name="href">mailto:<xsl:value-of select="$email"/></xsl:attribute>
     444            </xsl:if>
     445            <span class="email"><xsl:value-of select="$email"/></span>
     446          </a>
    434447        </span>
    435       </xsl:if>
     448      </xsl:for-each>
    436449      <xsl:if test="address/uri">
    437450        <span class="vcardline">
     
    475488    <!-- emit it -->
    476489    <xsl:choose>
    477       <xsl:when test="function-available('msxsl:node-set')">
    478         <xsl:apply-templates select="msxsl:node-set($copyright)"/>
    479       </xsl:when>
    480490      <xsl:when test="function-available('exslt:node-set')">
    481491        <xsl:apply-templates select="exslt:node-set($copyright)"/>
     
    539549    <table xmlns="http://www.w3.org/1999/xhtml" summary="header information" class="header" border="0" cellpadding="1" cellspacing="1">
    540550      <xsl:choose>
    541         <xsl:when test="function-available('msxsl:node-set')">
    542           <xsl:call-template name="emitheader">
    543             <xsl:with-param name="lc" select="msxsl:node-set($leftColumn)"/>   
    544             <xsl:with-param name="rc" select="msxsl:node-set($rightColumn)"/>   
    545           </xsl:call-template>
    546         </xsl:when>   
    547551        <xsl:when test="function-available('exslt:node-set')">
    548552          <xsl:call-template name="emitheader">
     
    589593    <!-- emit it -->
    590594    <xsl:choose>
    591       <xsl:when test="function-available('msxsl:node-set')">
    592         <xsl:apply-templates select="msxsl:node-set($preamble)"/>
    593       </xsl:when>
    594595      <xsl:when test="function-available('exslt:node-set')">
    595596        <xsl:apply-templates select="exslt:node-set($preamble)"/>
     
    936937  <!-- check for reference to reference -->
    937938  <xsl:variable name="anchor" select="@anchor"/>
    938   <xsl:if test="not(ancestor::ed:del) and not(//xref[@target=$anchor])">
    939     <xsl:message>WARNING: unused reference '<xsl:value-of select="@anchor"/>'<xsl:call-template name="lineno"/></xsl:message>
     939  <xsl:if test="not(ancestor::ed:del) and not(key('xref-item',$anchor))">
     940    <xsl:call-template name="warning">
     941      <xsl:with-param name="inline" select="'no'"/>
     942      <xsl:with-param name="msg">unused reference '<xsl:value-of select="@anchor"/>'</xsl:with-param>
     943    </xsl:call-template>
    940944  </xsl:if>
    941945
     
    11741178  <!-- conformance checks -->
    11751179  <xsl:if test="$xml2rfc-symrefs!='no' and $xml2rfc-symrefs!='yes' and //reference">
    1176     <xsl:message>WARNING: symrefs PI not specified; default has changed from 'no' to 'yes'.</xsl:message>
     1180    <xsl:call-template name="warning">
     1181      <xsl:with-param name="inline" select="'no'"/>
     1182      <xsl:with-param name="msg">symrefs PI not specified; default has changed from 'no' to 'yes'.</xsl:with-param>
     1183    </xsl:call-template>
    11771184  </xsl:if>
    11781185 
     
    15251532
    15261533  <xsl:variable name="target" select="@target"/>
    1527   <xsl:variable name="node" select="$src//*[@anchor=$target]"/>
     1534  <xsl:variable name="node" select="key('anchor-item',$target)"/>
    15281535  <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>
    15291536
     
    15941601</xsl:template>
    15951602               
     1603<xsl:key name="iref-xanch" match="iref[@x:for-anchor]" use="@x:for-anchor"/>           
     1604               
    15961605<xsl:template match="xref[not(node())]">
    15971606
     
    15991608  <xsl:variable name="target" select="@target"/>
    16001609  <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>
    1601   <xsl:variable name="node" select="$src//*[@anchor=$target]"/>
     1610  <xsl:variable name="node" select="key('anchor-item',$target)"/>
    16021611  <xsl:if test="count($node)=0 and not(ancestor::ed:del)">
    16031612    <xsl:call-template name="error">
     
    16121621      <a xmlns="http://www.w3.org/1999/xhtml" href="#{@target}">
    16131622        <!-- insert id when a backlink to this xref is needed in the index -->
    1614         <xsl:if test="//iref[@x:for-anchor=$target] | //iref[@x:for-anchor='' and ../@anchor=$target]">
     1623        <xsl:if test="key('iref-xanch',$target) | key('iref-xanch','')[../@anchor=$target]">
    16151624          <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
    16161625        </xsl:if>
     
    26172626  background-color: yellow;
    26182627}
    2619 <xsl:if test="//ed:del|//ed:replace|//ed:ins">del {
     2628<xsl:if test="$has-edits">del {
    26202629  color: red;
    26212630  text-decoration: line-through;
     
    29602969                        <xsl:text>  </xsl:text>
    29612970                       
    2962                         <xsl:variable name="rs" select="//xref[@target=current()/@anchor] | . | //reference[@anchor=concat('deleted-',current()/@anchor)]"/>
     2971                        <xsl:variable name="rs" select="key('xref-item',current()/@anchor) | . | key('anchor-item',concat('deleted-',current()/@anchor))"/>
     2972                       
    29632973                        <xsl:for-each select="$rs">
    29642974                          <xsl:call-template name="insertSingleXref"/>
     
    29752985                                <li class="indline1">
    29762986                                  <em>
    2977                                     <xsl:text>Section </xsl:text>
     2987                                    <xsl:choose>
     2988                                      <xsl:when test="translate(substring(@x:sec,1,1),$ucase,'')=''">
     2989                                        <xsl:text>Appendix </xsl:text>
     2990                                      </xsl:when>
     2991                                      <xsl:otherwise>
     2992                                        <xsl:text>Section </xsl:text>
     2993                                      </xsl:otherwise>
     2994                                    </xsl:choose>
    29782995                                    <xsl:value-of select="@x:sec"/>
    29792996                                  </em>
     
    29983015                                  <li class="indline1">
    29993016                                    <em>
    3000                                       <xsl:text>Section </xsl:text>
    3001                                       <xsl:for-each select="$doc//*[@anchor=substring-after(current()/@x:rel,'#')]">
    3002                                         <xsl:call-template name="get-section-number"/>
    3003                                       </xsl:for-each>
     3017                                      <xsl:variable name="sec">
     3018                                        <xsl:for-each select="$doc//*[@anchor=substring-after(current()/@x:rel,'#')]">
     3019                                          <xsl:call-template name="get-section-number"/>
     3020                                        </xsl:for-each>
     3021                                      </xsl:variable>
     3022                                      <xsl:choose>
     3023                                        <xsl:when test="translate(substring($sec,1,1),$ucase,'')=''">
     3024                                          <xsl:text>Appendix </xsl:text>
     3025                                        </xsl:when>
     3026                                        <xsl:otherwise>
     3027                                          <xsl:text>Section </xsl:text>
     3028                                        </xsl:otherwise>
     3029                                      </xsl:choose>
     3030                                      <xsl:value-of select="$sec"/>
    30043031                                    </em>
    30053032                                    <xsl:text>  </xsl:text>
     
    30203047                    <xsl:if test="generate-id(.) = generate-id(key('index-item',concat(@item,@anchor)))">
    30213048                      <xsl:variable name="item" select="@item"/>
    3022                       <xsl:variable name="in-artwork" select="count(//iref[@item=$item and @primary='true' and ancestor::artwork])!=0"/>
     3049                      <xsl:variable name="in-artwork" select="key('index-item',$item)[@primary='true' and ancestor::artwork]"/>
    30233050                         
    30243051                      <li class="indline1">
     
    30343061                       
    30353062                        <xsl:variable name="irefs3" select="key('index-item',@item)[not(@subitem) or @subitem='']"/>
    3036                         <xsl:variable name="xrefs3" select="//xref[@target=$irefs3[@x:for-anchor='']/../@anchor or @target=$irefs3/@x:for-anchor]"/>
    3037                         <xsl:variable name="extrefs3" select="//x:ref[.=$irefs3[@x:for-anchor='']/../@anchor or .=$irefs3/@x:for-anchor]"/>
     3063                        <xsl:variable name="xrefs3" select="key('xref-item',$irefs3[@x:for-anchor='']/../@anchor) | key('xref-item',$irefs3/@x:for-anchor)"/>
     3064                        <xsl:variable name="extrefs3" select="key('extref-item',$irefs3[@x:for-anchor='']/../@anchor) | key('extref-item',$irefs3/@x:for-anchor)"/>
    30383065
    30393066                        <xsl:for-each select="$irefs3|$xrefs3|$extrefs3">
     
    30513078                 
    30523079                                <xsl:variable name="itemsubitem" select="concat(@item,'..',@subitem)"/>
    3053                                 <xsl:variable name="in-artwork2" select="count(//iref[concat(@item,'..',@subitem)=$itemsubitem and @primary='true' and ancestor::artwork])!=0"/>
     3080                                <xsl:variable name="in-artwork2" select="key('index-item-subitem',concat(@item,'..',@subitem))[@primary='true' and ancestor::artwork]"/>
    30543081                 
    30553082                                <li class="indline1">
     
    30663093                                   
    30673094                                  <xsl:variable name="irefs4" select="key('index-item-subitem',concat(@item,'..',@subitem))"/>
    3068                                   <xsl:variable name="xrefs4" select="//xref[@target=$irefs4[@x:for-anchor='']/../@anchor or @target=$irefs4/@x:for-anchor]"/>
    3069                                   <xsl:variable name="extrefs4" select="//x:ref[.=$irefs4[@x:for-anchor='']/../@anchor or .=$irefs4/@x:for-anchor]"/>
     3095                                  <xsl:variable name="xrefs4" select="key('xref-item',$irefs4[@x:for-anchor='']/../@anchor) | key('xref-item',$irefs4/@x:for-anchor)"/>
     3096                                  <xsl:variable name="extrefs4" select="key('extref-item',$irefs4[@x:for-anchor='']/../@anchor) | key('extref-item',$irefs4/@x:for-anchor)"/>
    30703097
    30713098                                  <xsl:for-each select="$irefs4|$xrefs4|$extrefs4">
     
    37053732
    37063733<!-- internal ref support -->
     3734<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"/>
     3735
    37073736<xsl:template match="x:ref">
    37083737  <xsl:variable name="val" select="."/>
    3709   <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)]"/>
     3738<!--  <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)]"/> -->
     3739  <xsl:variable name="target" select="key('anchor-item',$val) | key('anchor-item-alias',$val)"/>
    37103740  <xsl:variable name="irefs" select="//iref[@x:for-anchor=$val]"/>
    37113741  <xsl:choose>
     
    37203750    </xsl:when>
    37213751    <xsl:otherwise>
    3722       <xsl:message>WARNING: internal link target for '<xsl:value-of select="."/>' does not exist.<xsl:call-template name="lineno"/></xsl:message>
     3752      <xsl:call-template name="warning">
     3753        <xsl:with-param name="inline" select="'no'"/>
     3754        <xsl:with-param name="msg">internal link target for '<xsl:value-of select="."/>' does not exist.</xsl:with-param>
     3755      </xsl:call-template>
    37233756      <xsl:value-of select="."/>
    37243757    </xsl:otherwise>
     
    38263859<xsl:template match="x:span">
    38273860  <xsl:apply-templates/>
     3861</xsl:template>
     3862
     3863<!-- ABNF support -->
     3864<xsl:template name="to-abnf-char-sequence">
     3865  <xsl:param name="chars"/>
     3866 
     3867  <xsl:variable name="c" select="substring($chars,1,1)"/>
     3868  <xsl:variable name="r" select="substring($chars,2)"/>
     3869   
     3870  <xsl:choose>
     3871    <xsl:when test="$c='A'">41</xsl:when>
     3872    <xsl:when test="$c='B'">42</xsl:when>
     3873    <xsl:when test="$c='C'">43</xsl:when>
     3874    <xsl:when test="$c='D'">44</xsl:when>
     3875    <xsl:when test="$c='E'">45</xsl:when>
     3876    <xsl:when test="$c='F'">46</xsl:when>
     3877    <xsl:when test="$c='G'">47</xsl:when>
     3878    <xsl:when test="$c='H'">48</xsl:when>
     3879    <xsl:when test="$c='I'">49</xsl:when>
     3880    <xsl:when test="$c='J'">4A</xsl:when>
     3881    <xsl:when test="$c='K'">4B</xsl:when>
     3882    <xsl:when test="$c='L'">4C</xsl:when>
     3883    <xsl:when test="$c='M'">4D</xsl:when>
     3884    <xsl:when test="$c='N'">4E</xsl:when>
     3885    <xsl:when test="$c='O'">4F</xsl:when>
     3886    <xsl:when test="$c='P'">50</xsl:when>
     3887    <xsl:when test="$c='Q'">51</xsl:when>
     3888    <xsl:when test="$c='R'">52</xsl:when>
     3889    <xsl:when test="$c='S'">53</xsl:when>
     3890    <xsl:when test="$c='T'">54</xsl:when>
     3891    <xsl:when test="$c='U'">55</xsl:when>
     3892    <xsl:when test="$c='V'">56</xsl:when>
     3893    <xsl:when test="$c='W'">57</xsl:when>
     3894    <xsl:when test="$c='X'">58</xsl:when>
     3895    <xsl:when test="$c='Y'">59</xsl:when>
     3896    <xsl:when test="$c='Z'">5A</xsl:when>
     3897    <xsl:when test="$c='a'">61</xsl:when>
     3898    <xsl:when test="$c='b'">62</xsl:when>
     3899    <xsl:when test="$c='c'">63</xsl:when>
     3900    <xsl:when test="$c='d'">64</xsl:when>
     3901    <xsl:when test="$c='e'">65</xsl:when>
     3902    <xsl:when test="$c='f'">66</xsl:when>
     3903    <xsl:when test="$c='g'">67</xsl:when>
     3904    <xsl:when test="$c='h'">68</xsl:when>
     3905    <xsl:when test="$c='i'">69</xsl:when>
     3906    <xsl:when test="$c='j'">6A</xsl:when>
     3907    <xsl:when test="$c='k'">6B</xsl:when>
     3908    <xsl:when test="$c='l'">6C</xsl:when>
     3909    <xsl:when test="$c='m'">6D</xsl:when>
     3910    <xsl:when test="$c='n'">6E</xsl:when>
     3911    <xsl:when test="$c='o'">6F</xsl:when>
     3912    <xsl:when test="$c='p'">70</xsl:when>
     3913    <xsl:when test="$c='q'">71</xsl:when>
     3914    <xsl:when test="$c='r'">72</xsl:when>
     3915    <xsl:when test="$c='s'">73</xsl:when>
     3916    <xsl:when test="$c='t'">74</xsl:when>
     3917    <xsl:when test="$c='u'">75</xsl:when>
     3918    <xsl:when test="$c='v'">76</xsl:when>
     3919    <xsl:when test="$c='w'">77</xsl:when>
     3920    <xsl:when test="$c='x'">78</xsl:when>
     3921    <xsl:when test="$c='y'">79</xsl:when>
     3922    <xsl:when test="$c='z'">7A</xsl:when>
     3923    <xsl:otherwise>
     3924      <xsl:text>??</xsl:text>
     3925      <xsl:call-template name="error">
     3926        <xsl:with-param name="msg" select="concat('unexpected character in ABNF char sequence: ',substring($chars,1,1))"/>
     3927      </xsl:call-template>
     3928    </xsl:otherwise>
     3929  </xsl:choose>
     3930
     3931  <xsl:if test="$r!=''">
     3932    <xsl:text>.</xsl:text>
     3933    <xsl:call-template name="to-abnf-char-sequence">
     3934      <xsl:with-param name="chars" select="$r"/>
     3935    </xsl:call-template>
     3936  </xsl:if>
     3937 
     3938</xsl:template>
     3939
     3940<xsl:template match="x:abnf-char-sequence">
     3941  <xsl:choose>
     3942    <xsl:when test="substring(.,1,1) != '&#34;' or substring(.,string-length(.),1) != '&#34;'">
     3943      <xsl:call-template name="error">
     3944        <xsl:with-param name="msg" select="'contents of x:abnf-char-sequence needs to be quoted.'"/>
     3945      </xsl:call-template>
     3946    </xsl:when>
     3947    <xsl:otherwise>
     3948      <xsl:text>%x</xsl:text>
     3949      <xsl:call-template name="to-abnf-char-sequence">
     3950        <xsl:with-param name="chars" select="substring(.,2,string-length(.)-2)"/>
     3951      </xsl:call-template>
     3952    </xsl:otherwise>
     3953  </xsl:choose>
    38283954</xsl:template>
    38293955
     
    45174643      </dt>
    45184644      <dd>
    4519         <xsl:value-of select="."/>
     4645        <xsl:apply-templates select="node()"/>
    45204646        <xsl:if test="@source"> --<xsl:value-of select="@source"/></xsl:if>
    45214647      </dd>
     
    46234749    <xsl:text>http://greenbytes.de/tech/webdav/rfc2629.xslt, </xsl:text>
    46244750    <!-- when RCS keyword substitution in place, add version info -->
    4625     <xsl:if test="contains('$Revision: 1.367 $',':')">
    4626       <xsl:value-of select="concat('Revision ',normalize-space(translate(substring-after('$Revision: 1.367 $', 'Revision: '),'$','')),', ')"/>
     4751    <xsl:if test="contains('$Revision: 1.379 $',':')">
     4752      <xsl:value-of select="concat('Revision ',normalize-space(translate(substring-after('$Revision: 1.379 $', 'Revision: '),'$','')),', ')"/>
    46274753    </xsl:if>
    4628     <xsl:if test="contains('$Date: 2008-05-19 13:00:19 $',':')">
    4629       <xsl:value-of select="concat(normalize-space(translate(substring-after('$Date: 2008-05-19 13:00:19 $', 'Date: '),'$','')),', ')"/>
     4754    <xsl:if test="contains('$Date: 2008-07-06 13:38:32 $',':')">
     4755      <xsl:value-of select="concat(normalize-space(translate(substring-after('$Date: 2008-07-06 13:38:32 $', 'Date: '),'$','')),', ')"/>
    46304756    </xsl:if>
    46314757    <xsl:value-of select="concat('XSLT vendor: ',system-property('xsl:vendor'),' ',system-property('xsl:vendor-url'))"/>
     
    46574783
    46584784<xsl:template name="get-section-number">
    4659   <xsl:variable name="hasEdits" select="count(//ed:del|//ed:ins)!=0"/>
    46604785  <xsl:variable name="anchor" select="@anchor"/>
    46614786  <xsl:choose>
     
    46634788      <xsl:value-of select="@x:fixed-section-number"/>
    46644789    </xsl:when>
    4665     <xsl:when test="$hasEdits or ancestor::*/@x:fixed-section-number">
     4790    <xsl:when test="$has-edits or ancestor::*/@x:fixed-section-number">
    46664791      <xsl:call-template name="sectionnumberAndEdits"/>
    46674792    </xsl:when>
     
    47094834
    47104835<xsl:template name="get-section-type">
    4711   <xsl:param name="prec"/>
     4836  <xsl:param name="prec"/> <!-- TODO: check this, it's unused -->
    47124837  <xsl:choose>
    47134838    <xsl:when test="ancestor::back">Appendix</xsl:when>
     
    47544879    </xsl:otherwise>
    47554880  </xsl:choose>
     4881</xsl:template>
     4882
     4883<!-- checking for email element -->
     4884<xsl:template name="extract-email">
     4885  <xsl:variable name="email" select="normalize-space(.)"/>
     4886  <xsl:if test="string-length(.) != string-length($email) or contains($email,' ')">
     4887    <xsl:call-template name="warning">
     4888      <xsl:with-param name="inline" select="'no'"/>
     4889      <xsl:with-param name="msg">excessive whitespace in email address: '<xsl:value-of select="."/>'</xsl:with-param>
     4890    </xsl:call-template>
     4891  </xsl:if>
     4892 
     4893  <xsl:variable name="email2">
     4894    <xsl:choose>
     4895      <xsl:when test="starts-with($email,'mailto:')">
     4896        <xsl:call-template name="warning">
     4897          <xsl:with-param name="inline" select="'no'"/>
     4898          <xsl:with-param name="msg">email should not include URI scheme: '<xsl:value-of select="."/>'</xsl:with-param>
     4899        </xsl:call-template>
     4900        <xsl:value-of select="substring($email, 1 + string-length('mailto:'))"/>
     4901      </xsl:when>
     4902      <xsl:otherwise>
     4903        <xsl:value-of select="$email"/>
     4904      </xsl:otherwise>
     4905    </xsl:choose>
     4906  </xsl:variable>
     4907 
     4908  <xsl:value-of select="$email2"/>
    47564909</xsl:template>
    47574910
     
    47984951  </xsl:if>
    47994952</xsl:template>
     4953
     4954<!-- define exslt:node-set for msxml -->       
     4955<msxsl:script language="JScript" implements-prefix="exslt">
     4956  this['node-set'] = function (x) {
     4957    return x;
     4958  }
     4959</msxsl:script>
    48004960
    48014961<!-- date handling -->
Note: See TracChangeset for help on using the changeset viewer.