Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

PrettyPrintXslt

From ZeroWiki

<?xml version="1.0" encoding="ISO-8859-1"?>

<?xml-stylesheet href="PrettyPrintXslt" type="text/xml"?>


<xsl:stylesheet version="1.0"

               xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
               xmlns:verb="http://informatik.hu-berlin.de/xmlverbatim"
               exclude-result-prefixes="verb">
  <xsl:output method="html" omit-xml-declaration="yes" indent="no"/>
  <xsl:template match="/">
     <xsl:apply-templates select="." mode="xmlverb" />
  </xsl:template>
  <xsl:template match="/" mode="xmlverb">
     <xsl:text>

</xsl:text>

     <xsl:comment>
        <xsl:text> converted by xmlverbatim.xsl 1.0.2, (c) O. Becker </xsl:text>
     </xsl:comment>
     <xsl:text>

</xsl:text>

        <xsl:apply-templates mode="xmlverb">
           <xsl:with-param name="root" select="true()"/>
        </xsl:apply-templates>
     <xsl:text>

</xsl:text>

  </xsl:template>
  <xsl:template match="verb:wrapper">
     <xsl:apply-templates mode="xmlverb" />
  </xsl:template>
  <xsl:template match="verb:wrapper" mode="xmlverb">
     <xsl:apply-templates mode="xmlverb" />
  </xsl:template>
  <xsl:template match="*" mode="xmlverb">
     <xsl:param name="root" />
     <xsl:text><</xsl:text>
     <xsl:variable name="ns-prefix"
                   select="substring-before(name(),':')" />
     <xsl:if test="$ns-prefix != ">
        
           <xsl:value-of select="$ns-prefix"/>
        
        <xsl:text>:</xsl:text>
     </xsl:if>
     
        <xsl:value-of select="local-name()"/>
     
     <xsl:variable name="pns" select="../namespace::*"/>
     <xsl:if test="$pnsname()= and not(namespace::*name()=)">
        
           <xsl:text> xmlns</xsl:text>
        
        <xsl:text>=""</xsl:text>
     </xsl:if>
     <xsl:for-each select="namespace::*">
        <xsl:if test="not($pns[name()=name(current()) and 
                          .=current()])">
           <xsl:call-template name="xmlverb-ns" />
        </xsl:if>
     </xsl:for-each>
     <xsl:for-each select="@*">
        <xsl:call-template name="xmlverb-attrs" />
     </xsl:for-each>
     <xsl:choose>
        <xsl:when test="count(*)=0 and .=">
           <xsl:text> /></xsl:text>
        </xsl:when>
        <xsl:otherwise>
           <xsl:text>></xsl:text>
           <xsl:apply-templates mode="xmlverb" />
           <xsl:text></</xsl:text>
           <xsl:if test="$ns-prefix != ">
              
                 <xsl:value-of select="$ns-prefix"/>
              
              <xsl:text>:</xsl:text>
           </xsl:if>
           
              <xsl:value-of select="local-name()"/>
           
           <xsl:text>></xsl:text>
        </xsl:otherwise>
     </xsl:choose>
     <xsl:if test="$root">
<xsl:text>

</xsl:text></xsl:if>

  </xsl:template>
  <xsl:template name="xmlverb-attrs">
     <xsl:text> </xsl:text>
     
        <xsl:value-of select="name()"/>
     
     <xsl:text>="</xsl:text>
     
        <xsl:call-template name="html-replace-entities">
           <xsl:with-param name="text" select="normalize-space(.)" />
           <xsl:with-param name="attrs" select="true()" />
        </xsl:call-template>
     
     <xsl:text>"</xsl:text>
  </xsl:template>
  <xsl:template name="xmlverb-ns">
     <xsl:if test="name()!='xml'">
        
           <xsl:text> xmlns</xsl:text>
           <xsl:if test="name()!=">
              <xsl:text>:</xsl:text>
           </xsl:if>
           <xsl:value-of select="name()"/>
        
        <xsl:text>="</xsl:text>
        
           <xsl:value-of select="."/>
        
        <xsl:text>"</xsl:text>
     </xsl:if>
  </xsl:template>
  <xsl:template match="text()" mode="xmlverb">
     
        <xsl:call-template name="preformatted-output">
           <xsl:with-param name="text">
              <xsl:call-template name="html-replace-entities">
                 <xsl:with-param name="text" select="." />
              </xsl:call-template>
           </xsl:with-param>
        </xsl:call-template>
     
  </xsl:template>
  <xsl:template match="comment()" mode="xmlverb">
     <xsl:param name="root" />
     <xsl:text></xsl:text>
     <xsl:if test="$root">
<xsl:text>

</xsl:text></xsl:if>

  </xsl:template>
  <xsl:template match="processing-instruction()" mode="xmlverb">
     <xsl:param name="root" />
     <xsl:text><?</xsl:text>
     
        <xsl:value-of select="name()"/>
     
     <xsl:if test=".!=">
        <xsl:text> </xsl:text>
        
           <xsl:value-of select="."/>
        
     </xsl:if>
     <xsl:text>?></xsl:text>
     <xsl:if test="$root">
<xsl:text>

</xsl:text></xsl:if>

  </xsl:template>


  <xsl:template name="html-replace-entities">
     <xsl:param name="text" />
     <xsl:param name="attrs" />
     <xsl:variable name="tmp">
        <xsl:call-template name="replace-substring">
           <xsl:with-param name="from" select="'>'" />
           <xsl:with-param name="to" select="'>'" />
           <xsl:with-param name="value">
              <xsl:call-template name="replace-substring">
                 <xsl:with-param name="from" select="'<'" />
                 <xsl:with-param name="to" select="'<'" />
                 <xsl:with-param name="value">
                    <xsl:call-template name="replace-substring">
                       <xsl:with-param name="from" 
                                       select="'&'" />
                       <xsl:with-param name="to" 
                                       select="'&'" />
                       <xsl:with-param name="value" 
                                       select="$text" />
                    </xsl:call-template>
                 </xsl:with-param>
              </xsl:call-template>
           </xsl:with-param>
        </xsl:call-template>
     </xsl:variable>
     <xsl:choose>
        <xsl:when test="$attrs">
           <xsl:call-template name="replace-substring">
              <xsl:with-param name="from" select="'

'" />

              <xsl:with-param name="to" select="'
'" />
              <xsl:with-param name="value">
                 <xsl:call-template name="replace-substring">
                    <xsl:with-param name="from" 
                                    select="'"'" />
                    <xsl:with-param name="to" 
                                    select="'"'" />
                    <xsl:with-param name="value" select="$tmp" />
                 </xsl:call-template>
              </xsl:with-param>
           </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
           <xsl:value-of select="$tmp" />
        </xsl:otherwise>
     </xsl:choose>
  </xsl:template>
  <xsl:template name="replace-substring">
     <xsl:param name="value" />
     <xsl:param name="from" />
     <xsl:param name="to" />
     <xsl:choose>
        <xsl:when test="contains($value,$from)">
           <xsl:value-of select="substring-before($value,$from)" />
           <xsl:value-of select="$to" />
           <xsl:call-template name="replace-substring">
              <xsl:with-param name="value" 
                              select="substring-after($value,$from)" />
              <xsl:with-param name="from" select="$from" />
              <xsl:with-param name="to" select="$to" />
           </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
           <xsl:value-of select="$value" />
        </xsl:otherwise>
     </xsl:choose>
  </xsl:template>
  <xsl:template name="preformatted-output">
     <xsl:param name="text" />
     <xsl:call-template name="output-nl">
        <xsl:with-param name="text">
           <xsl:call-template name="replace-substring">
              <xsl:with-param name="value"
                              select="translate($text,' ',' ')" />
              <xsl:with-param name="from" select="'	'" />
              <xsl:with-param name="to" 
                              select="'        '" />
           </xsl:call-template>
        </xsl:with-param>
     </xsl:call-template>
  </xsl:template>
  <xsl:template name="output-nl">
     <xsl:param name="text" />
     <xsl:choose>
        <xsl:when test="contains($text,'

')">

           <xsl:value-of select="substring-before($text,'

')" />

           
<xsl:text>

</xsl:text>

           <xsl:call-template name="output-nl">
              <xsl:with-param name="text" 
                              select="substring-after($text,'

')" />

           </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
           <xsl:value-of select="$text" />
        </xsl:otherwise>
     </xsl:choose>
  </xsl:template>

</xsl:stylesheet>