DanC / urlp

No description has been added.

Clone this repository (size: 151.6 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/DanC/urlp/
commit 72: 8815a3dcb6aa
parent 71: 8110f5244483
branch: default
tags: tip
fix draft number
Dan Connolly
10 months ago
urlp / wah5 / ietf.xsl
r72:8815a3dcb6aa 337 loc 8.1 KB embed / history / annotate / raw /
<xsl:transform
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:h="http://www.w3.org/1999/xhtml"
    version="1.0"
    exclude-result-prefixes="h"
    >

<xsl:output
    method="xml"
    indent="yes"
    doctype-system='rfc2629.dtd'
    />

<xsl:template match="h:html">
  <xsl:variable name="docname"
		select="h:head/h:meta[@name='docname']/@content" />
  <rfc ipr="full3978">
    <xsl:if test="$docname">
      <xsl:attribute name="docName">
	<xsl:value-of select="$docname"/>
      </xsl:attribute>
    </xsl:if>
    <xsl:apply-templates />
  </rfc>
</xsl:template>

<xsl:template match="h:head">
  <!-- munch munch -->
</xsl:template>

<xsl:template match="h:body">
  <xsl:apply-templates />
</xsl:template>


<xsl:template match="h:div[@class='head']">
  <front>
    <xsl:apply-templates />
    <abstract>
      <xsl:apply-templates select="//h:div[h:h2/h:a/@id='abstract']/*" />
    </abstract>
  </front>
</xsl:template>

<xsl:template match="h:h1">
  <title>
    <xsl:apply-templates />
  </title>
</xsl:template>

<xsl:template match="h:dt[ancestor::h:div/@class='head']" >
  <!-- drop Editors: label-->
</xsl:template>

<xsl:template match="h:dd[ancestor::h:div/@class='head']" >
  <xsl:variable name="fn" select="substring-before(., ',')" />
  <xsl:variable name="surname" select="substring-after($fn, ' ')" />
  <xsl:variable name="initials" select="substring($fn, 1, 1)" />
  <xsl:variable name="email" select=".//*[@class='email']" />
  <xsl:variable name="org" select=".//*[@class='org']" />
  <xsl:variable name="uri" select=".//h:a/@href" />

  <author fullname="{$fn}" initials="{$initials}" surname="{$surname}">
    <organization><xsl:value-of select="$org" /></organization>
    <address>
      <email><xsl:value-of select="$email" /></email>
      <uri><xsl:value-of select="$uri" /></uri>
    </address>
  </author>
</xsl:template>


<xsl:template match="h:h2[ancestor::h:div/@class='head']" >
  <!-- date must be written: DD Month YYYY-->
  <xsl:variable name="dmy"
		select="normalize-space(text())" />
  <xsl:variable name="day"
		select="substring-before($dmy, ' ')" />
  <xsl:variable name="month"
		select="substring-before(substring-after($dmy, ' '), ' ')" />

  <xsl:variable name="year"
		select="substring-after(substring-after($dmy, ' '), ' ')" />

  <date day="{$day}" month="{$month}" year="{$year}" />
</xsl:template>

<xsl:template match="//h:div[h:h2/h:a/@id='abstract']">
  <!-- don't repeat -->
</xsl:template>

<xsl:template match="h:p[@class='copyright']">
  <!-- "Note that text relating to the memo's status, copyright
       notice, or table of contents is not included in the document's
       markup — this is automatically inserted by an XML application
       when it produces either a text or HTML version of the
       document. " - 2.2.7.  Status, Copyright Notice, Table of
       Contents -->
</xsl:template>


<xsl:template match="h:div[h:h2/h:a/@id='status']" >
  <!-- elide -->
</xsl:template>

<xsl:template match="h:div[@class='toc']" >
  <!-- elide -->
</xsl:template>

<xsl:template match="h:h2" >
  <!-- elide -->
</xsl:template>

<xsl:template match="h:hr" >
  <!-- elide -->
</xsl:template>



<xsl:template match="h:div[@class='back']">
  <back>
    <xsl:apply-templates mode="back"/>
  </back>
</xsl:template>

<xsl:template match="h:div[h:h2/@id='references']" mode="back">
  <references>
    <xsl:for-each select="h:dl/h:dt">
      <reference anchor="{h:a/@name}">

	<xsl:variable name="urlxx"
		      select="substring-after(following-sibling::h:dd[position()=1]/text(), 'p:')" />
	<xsl:variable name="urlx"
		      select="substring-before($urlxx, '&gt;')" />
	<xsl:if test="string-length($urlx) &gt; 0">
	  <xsl:attribute name="target">
	    <xsl:value-of select="concat('http', $urlx)" />
	  </xsl:attribute>
	</xsl:if>

	<xsl:apply-templates mode="refs"
			     select="./following-sibling::h:dd[position()=1]"/>

	<xsl:if test="starts-with(., 'RFC ')">
	  <xsl:variable name="rfcnum" select="substring-after(., ' ')" />
	  <seriesInfo name="RFC" value="{$rfcnum}" />
	</xsl:if>

      </reference>
    </xsl:for-each>
  </references>
</xsl:template>


<xsl:template match="h:dd" mode="refs">
  <xsl:variable name="authors"
		select="substring-before(normalize-space(.), '&#34;')" />
  <xsl:variable name="rest1"
		select="substring-after(normalize-space(.), '&#34;')" />

  <xsl:variable name="title"
		select="substring-before($rest1, '&#34;')" />
  <xsl:variable name="rest2"
		select="substring-after($rest1, '&#34;')" />
  <!-- comma after title -->
  <xsl:variable name="rest3"
		select="substring-after($rest2, ',')" />
  <!-- comma after RFC NNNN  -->
  <xsl:variable name="rest4"
		select="normalize-space(substring-after($rest3, ','))" />

  <xsl:variable name="date"
		select="substring-before($rest4, '.')" />
  <xsl:variable name="month"
		select="substring-before($date, ' ')" />
  <xsl:variable name="year"
		select="substring-after($date, ' ')" />
  <front>
    <title><xsl:value-of select="$title" /></title>
    <!-- @@ recur over authors -->
    <author fullname="{$authors}" >
      <organization></organization>
    </author>
    <date month="{$month}" year="{$year}" />
  </front>
</xsl:template>


<xsl:template match="h:div[@class='body']">
  <middle>
    <xsl:apply-templates />
  </middle>
</xsl:template>

<xsl:template match="h:div[@class='div1']">
  <xsl:variable name="label" select="h:h2/text()"/>
  <xsl:variable name="anchor" select="h:h2/@id" />

  <section title="{$label}" anchor="{$anchor}">
    <xsl:apply-templates />
  </section>
</xsl:template>

<!-- hmm... messes up abstract?
<xsl:template match="h:div">
  <section>
    <xsl:apply-templates />
  </section>
</xsl:template>
-->




<xsl:template match="h:p">
  <t>
    <xsl:apply-templates />
  </t>
</xsl:template>


<!-- make up for mismatch between h:p and ietf:t -->
<xsl:template match="h:div[@class='t']">
  <t>
    <xsl:apply-templates />
  </t>
</xsl:template>


<xsl:template match="h:div[@class='ednote']">
  <!-- leave out of main body text -->
  <!-- perhaps use in an appendix -->
</xsl:template>



<xsl:template match="h:ol">
  <list style="numbers">
    <xsl:apply-templates />
  </list>
</xsl:template>

<xsl:template match="h:ul">
  <list style="symbols">
    <xsl:apply-templates />
  </list>
</xsl:template>

<xsl:template match="h:li">
  <xsl:choose>
    <xsl:when test="./h:p">
      <xsl:apply-templates />
    </xsl:when>
    <xsl:otherwise>
      <t>
	<xsl:apply-templates />
      </t>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>



<xsl:template match="h:dl[h:dt/h:dfn]">
  <list style="hanging">
    <xsl:for-each select="h:dd">
      <xsl:variable name="dt" select="./preceding-sibling::h:dt[position()=1]" />
      <t anchor="{$dt/h:dfn/@id}" hangText="{$dt}">
	<xsl:apply-templates />
      </t>
    </xsl:for-each>
  </list>
</xsl:template>

<xsl:template match="h:dl[@class='switch']" >
  <list style="hanging">
    <xsl:for-each select="h:dd">
      <xsl:variable name="dt" select="preceding-sibling::h:dt[position()=1]" />
      <t hangText="{$dt}">
	<xsl:apply-templates />
      </t>
    </xsl:for-each>
  </list>
</xsl:template>




<xsl:template match="h:span[@class='secno']">
  <!-- elide -->
</xsl:template>

<xsl:template match="h:em|h:i">
  <spanx style="emph">
	<xsl:apply-templates />
  </spanx>
</xsl:template>

<xsl:template match="h:dfn">
  <!-- @@ what to do with anchor? -->
  <spanx style="emph">
    <xsl:apply-templates />
  </spanx>
</xsl:template>

<xsl:template match="h:var">
  <spanx style="emph">
	<xsl:apply-templates />
  </spanx>
</xsl:template>

<xsl:template match="h:code">
  <spanx style="verb">
	<xsl:apply-templates />
  </spanx>
</xsl:template>




<!-- hypertext references -->
<xsl:template match="h:a[@href]">
  <xsl:variable name="target" select="substring(@href, 2)" />

  <xref target="{$target}">
    <xsl:apply-templates />
  </xref>
</xsl:template>

<!-- diagnostics -->
<xsl:template match="*">
  <xsl:message>warning: <xsl:value-of select="local-name()" />#<xsl:value-of select="@id" />[<xsl:value-of select="@class" />] in <xsl:value-of select="local-name(..)" />#<xsl:value-of select="../@id" />[<xsl:value-of select="../@class" />] not recognized.
  </xsl:message>
  <xsl:apply-templates />
</xsl:template>

</xsl:transform>