Category:Programming language:XSLT

From LiteratePrograms

Jump to: navigation, search

XSLT, XML Stylesheet Language for Transformations

XSLT has found most usage in transforming XML content into HTML.

As a language it is Turing complete. It can be quite complex and hence benefits from literate programming additions. Add these in another namespace and process for documentation by using another stylesheet. This example uses docbook, for documenting the stylesheets for docbook.

<!-- ============================================================ -->
<doc:mode name="m:graphical-admonition" xmlns="http://docbook.org/ns/docbook">
<refpurpose>Mode for processing admonitions with graphics</refpurpose>
<refdescription>
<para>There are two distinct presentational styles for admonitions, with
graphics and without. Processing an admonition in this mode produces
the graphical form.</para>
</refdescription>
</doc:mode>
<xsl:template match="db:note|db:important|db:warning|db:caution|db:tip"
	      mode="m:graphical-admonition">
  <xsl:variable name="titlepage"
		select="$titlepages/*[node-name(.)
			              = node-name(current())][1]"/>
  <xsl:variable name="admon.type">
    <xsl:choose>
      <xsl:when test="self::db:note">Note</xsl:when>
      <xsl:when test="self::db:warning">Warning</xsl:when>
      <xsl:when test="self::db:caution">Caution</xsl:when>
      <xsl:when test="self::db:tip">Tip</xsl:when>
      <xsl:when test="self::db:important">Important</xsl:when>
      <xsl:otherwise>Note</xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="alt">
    <xsl:call-template name="gentext">
      <xsl:with-param name="key" select="$admon.type"/>
    </xsl:call-template>
  </xsl:variable>
  <!-- I'd really rather not do this with a table, but getting the -->
  <!-- alignment with and without a title without using a table is -->
  <!-- painfully complicated. That said, the vertical spacing is   -->
  <!-- awfully complicated with a table. -->
  <div class="{f:admonition-class(.)}">
    <xsl:call-template name="id"/>
    <xsl:call-template name="class"/>
    <table border="0" cellspacing="0" cellpadding="4"
	   summary="Presentation of a {f:admonition-class(.)}">
      <tbody>
	<tr>
	  <td valign="top">
	    <span class="admon-graphic">
	      <img alt="{$alt}">
		<xsl:attribute name="src">
		  <xsl:call-template name="admonition-graphic"/>
		</xsl:attribute>
	      </img>
	    </span>
	  </td>
	  <td>
	    <xsl:if test="db:info/db:title[not(@ghost:title)
			                   or $admon.default.titles != 0]">
	      <div class="admon-title-text">
		<xsl:call-template name="titlepage">
		  <xsl:with-param name="content" select="$titlepage"/>
		</xsl:call-template>
	      </div>
	    </xsl:if>
	    <div class="admon-text">
	      <xsl:apply-templates/>
	    </div>
	  </td>
	</tr>
      </tbody>
    </table>
  </div>
</xsl:template>


Note the use of the db: prefixed items for documentation.


Articles in category "Programming language:XSLT"

There are 0 articles in this category.
Views