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="">
<refpurpose>Mode for processing admonitions with graphics</refpurpose>
<para>There are two distinct presentational styles for admonitions, with
graphics and without. Processing an admonition in this mode produces
the graphical form.</para>
<xsl:template match="db:note|db:important|db:warning|db:caution|db:tip"
  <xsl:variable name="titlepage"
			              = node-name(current())][1]"/>
  <xsl:variable name="admon.type">
      <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:variable name="alt">
    <xsl:call-template name="gentext">
      <xsl:with-param name="key" select="$admon.type"/>
  <!-- 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(.)}">
	  <td valign="top">
	    <span class="admon-graphic">
	      <img alt="{$alt}">
		<xsl:attribute name="src">
		  <xsl:call-template name="admonition-graphic"/>
	    <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"/>
	    <div class="admon-text">

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

Articles in category "Programming language:XSLT"

There are 0 articles in this category.