Expand | Collapse

◀ 16. Manipulating URIs18. Support for literate programming ▶

17. Stylesheet to nicely format XML markup

xsl:stylesheet id="stylesheet" exclude-result-prefixes="x2 lit" version="1.0" xml:lang="en"

xsl:template match="x2:blockcode[@class='xml']"
  <pre class="xml">
    xsl:call-template name="copy-id"
    xsl:apply-templates mode="quote-xml"
  </pre>


xsl:template match="x2:a" mode="quote-xml"
  <a>
    xsl:attribute name="href"
      xsl:call-template name="map-uri"
        xsl:with-param name="href" select="@lit:href"
      
    

    xsl:apply-templates
  </a>


xsl:template match="hs:xref" mode="quote-xml"
  <a>
    xsl:attribute name="href"
      xsl:call-template name="map-uri"
        xsl:with-param name="href" select="@href"
      
    
    
    xsl:call-template name="xref-label"
  </a>


xsl:template match="@lit:*" mode="quote-xml"


xsl:template match="xsl:*"
  <pre class="xml">
    xsl:call-template name="copy-id"
    xsl:apply-templates select="." mode="quote-xml"
  </pre>




xsl:template match="text()" mode="quote-xml"
  xsl:value-of select="."


xsl:template match="xsl:*" mode="quote-xml"
  xsl:param name="content" select="node()"

  <span class="xml-element">
  <b class="tag-name">
    xsl:value-of select="name(.)"
  </b>
  xsl:apply-templates select="attribute::*" mode="quote-xml"
  </span>

  xsl:apply-templates select="$content" mode="quote-xml"


xsl:template match="xsl:template/attribute::id" mode="quote-xml" priority="1.0"


xsl:template match="*" mode="quote-xml"
  xsl:param name="content" select="node()"

  xsl:text<
  xsl:value-of select="name(.)"
  xsl:apply-templates select="attribute::*" mode="quote-xml"

  xsl:choose
    xsl:when test="$content"
      xsl:text>
      xsl:apply-templates select="$content" mode="quote-xml"
      xsl:text</
      xsl:value-of select="name(.)"
      xsl:text>
    

    xsl:otherwise
      xsl:text />
    
  


xsl:template match="@*" mode="quote-xml"
  xsl:text 
  <i class="attr">xsl:value-of select="name(.)"</i>
  xsl:text="
  xsl:value-of select="."
  xsl:text"


xsl:template match="comment()" mode="quote-xml"
  xsl:text<--

  xsl:value-of select="."
  xsl:text
-->


xsl:template match="processing-instruction()" mode="quote-xml"
  xsl:text<?
  xsl:value-of select="local-name(.)"
  xsl:text 
  xsl:value-of select="."
  xsl:text?>


Formatted using xhtml2to1 by Steve Cheng.