source: draft-ietf-httpbis/latest/abnf2xml2rfc.xslt @ 427

Last change on this file since 427 was 427, checked in by julian.reschke@…, 11 years ago

ABNF appendix: group by first letter, add internal links to definitions (related to #36)

File size: 2.6 KB
Line 
1<xsl:transform
2  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3  xmlns:xs="http://www.w3.org/2001/XMLSchema"
4  xmlns:x="http://purl.org/net/xml2rfc/ext"
5  version="2.0"
6  exclude-result-prefixes="xs">
7
8<xsl:output method="xml" omit-xml-declaration="yes" indent="no"/>
9
10<xsl:param name="abnf"/> 
11 
12<xsl:template match="/">
13  <xsl:variable name="src" select="."/>
14  <xsl:variable name="collected" select="unparsed-text($abnf)"/>
15
16  <xsl:variable name="lines" as="xs:string*" select="tokenize($collected, '\r?\n')"/>
17 
18  <section title="Collected ABNF" anchor="collected.abnf">
19    <xsl:text>&#10;</xsl:text>
20    <figure>
21      <xsl:text>&#10;</xsl:text>
22      <artwork type="abnf" name="{$abnf}">
23        <xsl:for-each select="$lines">
24          <xsl:variable name="lineno" select="position()"/>
25          <xsl:variable name="sc1" select="substring(.,1,1)"/>
26          <xsl:variable name="sc0" select="substring($lines[$lineno - 1],1,1)"/>
27          <xsl:if test="$sc1!=' ' and $sc0!=' ' and $sc1!=$sc0">
28            <xsl:text>&#10;</xsl:text>
29          </xsl:if>
30          <xsl:analyze-string select="." regex='^([A-Za-z0-9\-]+) = ' flags="sm">
31            <xsl:matching-substring>
32              <xsl:variable name="term" select="regex-group(1)"/>
33              <xsl:choose>
34                <xsl:when test="$src//*[@anchor=$term] or $src//x:anchor-alias[@value=$term]">
35                  <x:ref><xsl:value-of select="$term"/></x:ref>
36                </xsl:when>
37                <xsl:otherwise>
38                  <xsl:value-of select="$term"/>
39                </xsl:otherwise>
40              </xsl:choose>
41              <xsl:text> = </xsl:text>
42            </xsl:matching-substring>
43            <xsl:non-matching-substring>
44              <xsl:value-of select="."/>
45            </xsl:non-matching-substring>
46          </xsl:analyze-string>
47          <xsl:text>&#10;</xsl:text>
48        </xsl:for-each>
49      </artwork>
50      <xsl:text>&#10;</xsl:text>
51    </figure> 
52    <xsl:text>&#10;</xsl:text>
53  </section>
54
55  <!-- check whether it's up-to-date... -->
56 
57  <xsl:if test="not(//section[@anchor='collected.abnf']) or normalize-space(//section[@anchor='collected.abnf']//artwork) != normalize-space($collected)">
58    <xsl:message>WARNING: appendix contained inside source document needs to be updated</xsl:message>
59    <!--<xsl:message>A: <xsl:value-of select="//section[@anchor='collected.abnf']//artwork"/></xsl:message>
60    <xsl:message>B: <xsl:value-of select="$collected"/></xsl:message>-->
61  </xsl:if>
62</xsl:template>
63 
64 
65</xsl:transform>
Note: See TracBrowser for help on using the repository browser.