[420] | 1 | <xsl:transform
|
---|
| 2 | xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
---|
[427] | 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">
|
---|
[420] | 7 |
|
---|
[427] | 8 | <xsl:output method="xml" omit-xml-declaration="yes" indent="no"/>
|
---|
| 9 |
|
---|
[420] | 10 | <xsl:param name="abnf"/>
|
---|
| 11 |
|
---|
| 12 | <xsl:template match="/">
|
---|
[427] | 13 | <xsl:variable name="src" select="."/>
|
---|
[421] | 14 | <xsl:variable name="collected" select="unparsed-text($abnf)"/>
|
---|
[420] | 15 |
|
---|
[427] | 16 | <xsl:variable name="lines" as="xs:string*" select="tokenize($collected, '\r?\n')"/>
|
---|
| 17 |
|
---|
| 18 | <section title="Collected ABNF" anchor="collected.abnf">
|
---|
[425] | 19 | <xsl:text> </xsl:text>
|
---|
[427] | 20 | <figure>
|
---|
| 21 | <xsl:text> </xsl:text>
|
---|
| 22 | <artwork type="abnf" name="{$abnf}">
|
---|
[454] | 23 | <xsl:for-each select="$lines[substring(.,1,2)!='; ']">
|
---|
| 24 |
|
---|
| 25 | <!-- Group by start character -->
|
---|
[427] | 26 | <xsl:variable name="lineno" select="position()"/>
|
---|
| 27 | <xsl:variable name="sc1" select="substring(.,1,1)"/>
|
---|
[428] | 28 | <xsl:variable name="sc0" select="x:laststartchar($lines, $lineno - 1)"/>
|
---|
[427] | 29 | <xsl:if test="$sc1!=' ' and $sc0!=' ' and $sc1!=$sc0">
|
---|
| 30 | <xsl:text> </xsl:text>
|
---|
| 31 | </xsl:if>
|
---|
[454] | 32 |
|
---|
| 33 | <!-- Add cross-refs for terms -->
|
---|
[427] | 34 | <xsl:analyze-string select="." regex='^([A-Za-z0-9\-]+) = ' flags="sm">
|
---|
| 35 | <xsl:matching-substring>
|
---|
| 36 | <xsl:variable name="term" select="regex-group(1)"/>
|
---|
| 37 | <xsl:choose>
|
---|
| 38 | <xsl:when test="$src//*[@anchor=$term] or $src//x:anchor-alias[@value=$term]">
|
---|
| 39 | <x:ref><xsl:value-of select="$term"/></x:ref>
|
---|
| 40 | </xsl:when>
|
---|
| 41 | <xsl:otherwise>
|
---|
| 42 | <xsl:value-of select="$term"/>
|
---|
| 43 | </xsl:otherwise>
|
---|
| 44 | </xsl:choose>
|
---|
| 45 | <xsl:text> = </xsl:text>
|
---|
| 46 | </xsl:matching-substring>
|
---|
| 47 | <xsl:non-matching-substring>
|
---|
| 48 | <xsl:value-of select="."/>
|
---|
| 49 | </xsl:non-matching-substring>
|
---|
| 50 | </xsl:analyze-string>
|
---|
[454] | 51 |
|
---|
[427] | 52 | <xsl:text> </xsl:text>
|
---|
| 53 | </xsl:for-each>
|
---|
| 54 | </artwork>
|
---|
| 55 | <xsl:text> </xsl:text>
|
---|
| 56 | </figure>
|
---|
| 57 | <xsl:text> </xsl:text>
|
---|
[454] | 58 |
|
---|
| 59 | <figure>
|
---|
| 60 | <preamble>ABNF diagnostics:</preamble>
|
---|
| 61 | <artwork type="inline">
|
---|
[537] | 62 | <xsl:text> </xsl:text>
|
---|
[454] | 63 | <xsl:for-each select="$lines[substring(.,1,2)='; ']">
|
---|
| 64 | <xsl:value-of select="."/>
|
---|
| 65 | <xsl:text> </xsl:text>
|
---|
| 66 | </xsl:for-each>
|
---|
| 67 | </artwork></figure>
|
---|
[421] | 68 | </section>
|
---|
[420] | 69 |
|
---|
[425] | 70 | <!-- check whether it's up-to-date... -->
|
---|
[454] | 71 | <xsl:variable name="src">
|
---|
| 72 | <xsl:for-each select="//section[@anchor='collected.abnf']//artwork">
|
---|
| 73 | <xsl:value-of select="."/>
|
---|
| 74 | </xsl:for-each>
|
---|
| 75 | </xsl:variable>
|
---|
[421] | 76 |
|
---|
[454] | 77 | <xsl:if test="not(//section[@anchor='collected.abnf']) or normalize-space($src) != normalize-space($collected)">
|
---|
[421] | 78 | <xsl:message>WARNING: appendix contained inside source document needs to be updated</xsl:message>
|
---|
[425] | 79 | <!--<xsl:message>A: <xsl:value-of select="//section[@anchor='collected.abnf']//artwork"/></xsl:message>
|
---|
[421] | 80 | <xsl:message>B: <xsl:value-of select="$collected"/></xsl:message>-->
|
---|
| 81 | </xsl:if>
|
---|
[420] | 82 | </xsl:template>
|
---|
[428] | 83 |
|
---|
| 84 | <xsl:function name="x:laststartchar">
|
---|
| 85 | <xsl:param name="lines"/>
|
---|
| 86 | <xsl:param name="position"/>
|
---|
[420] | 87 |
|
---|
[428] | 88 | <xsl:choose>
|
---|
| 89 | <xsl:when test="' '!=substring($lines[$position],1,1)">
|
---|
| 90 | <xsl:value-of select="substring($lines[$position],1,1)"/>
|
---|
| 91 | </xsl:when>
|
---|
| 92 | <xsl:otherwise>
|
---|
| 93 | <xsl:value-of select="x:laststartchar($lines, $position - 1)"/>
|
---|
| 94 | </xsl:otherwise>
|
---|
| 95 | </xsl:choose>
|
---|
| 96 | </xsl:function>
|
---|
[420] | 97 |
|
---|
[428] | 98 |
|
---|
[420] | 99 | </xsl:transform> |
---|