<?xml version="1.0"?>
<!-- Generated by NiceXSL 2.0.5 at Sun Sep 18 11:08:11 GMT 2005 -->
<xsl:stylesheet xmlns:f="http://okowa.org/XSLT/Format" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:param name="debug" select="false()"/>
    <xsl:param name="indentstr" select="'  '"/>
    <xsl:param name="breakstr" select="'&#10;'"/>
    <xsl:param name="xmldecl" select="'yes'"/>
    <xsl:param name="xmldecl-version" select="'1.0'"/>
    <xsl:param name="xmldecl-encoding" select="'utf-8'"/>
    <xsl:param name="xmldecl-standalone"/>
    <xsl:param name="doctype-public"/>
    <xsl:param name="doctype-system"/>
    <xsl:param name="doctype-content"/>
    <xsl:include href="formatrc.xsl"/>
    <xsl:output encoding="UTF-8" indent="no" method="text" omit-xml-declaration="yes" version="1.0"/>
    <xsl:variable name="root" select="/"/>
    <f:document>
        <f:xmldecl/>
        <f:doctype/>
        <f:root/>
    </f:document>
    <xsl:template match="/">
        <xsl:variable name="inside">
            <xsl:apply-templates mode="f:break-inside" select="."/>
        </xsl:variable>
        <xsl:variable name="child-ctx">
            <xsl:call-template name="f:child-context"/>
        </xsl:variable>
        <xsl:call-template name="f:walk">
            <xsl:with-param name="node" select="document('')/xsl:stylesheet/f:document/*[1]"/>
            <xsl:with-param name="depth" select="0"/>
            <xsl:with-param name="break" select="$inside"/>
            <xsl:with-param name="context" select="$child-ctx"/>
            <xsl:with-param name="space">
                <xsl:apply-templates mode="f:space" select="."/>
            </xsl:with-param>
            <xsl:with-param name="started" select="false()"/>
        </xsl:call-template>
        <xsl:variable name="last" select="node()[not(text() and normalize-space() = '')][last()]"/>
        <xsl:variable name="last-outside">
            <xsl:apply-templates mode="f:break-outside" select="$last"/>
        </xsl:variable>
        <xsl:call-template name="f:break">
            <xsl:with-param name="former" select="$last-outside"/>
            <xsl:with-param name="latter" select="$inside"/>
        </xsl:call-template>
    </xsl:template>
    <xsl:template name="f:walk">
        <xsl:param name="node"/>
        <xsl:param name="depth"/>
        <xsl:param name="break"/>
        <xsl:param name="context"/>
        <xsl:param name="space"/>
        <xsl:param name="started" select="true()"/>
        <xsl:if test="$node">
            <xsl:variable name="available">
                <xsl:apply-templates mode="f:available" select="$node">
                    <xsl:with-param name="space" select="$space"/>
                </xsl:apply-templates>
            </xsl:variable>
            <xsl:variable name="type">
                <xsl:apply-templates mode="f:display" select="$node"/>
            </xsl:variable>
            <xsl:variable name="outside">
                <xsl:apply-templates mode="f:break-outside" select="$node"/>
            </xsl:variable>
            <xsl:variable name="next-break">
                <xsl:choose>
                    <xsl:when test="$available">
                        <xsl:value-of select="$outside"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$break"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:variable>
            <xsl:if test="$debug">
                <xsl:value-of select="concat('[n:', name($node), ',a:', $available, ']')"/>
            </xsl:if>
            <xsl:if test="$available = 'yes'">
                <xsl:if test="$debug">
                    <xsl:value-of select="concat('[s:', $started, ',p:', $space, ',c:', $context, ',t:', $type, ']')"/>
                </xsl:if>
                <xsl:if test="$started and $space = 'default' and not($context = 'inline' and $type = 'inline')">
                    <xsl:call-template name="f:break">
                        <xsl:with-param name="former" select="$break"/>
                        <xsl:with-param name="latter" select="$outside"/>
                    </xsl:call-template>
                    <xsl:call-template name="f:indent">
                        <xsl:with-param name="depth" select="$depth"/>
                    </xsl:call-template>
                </xsl:if>
                <xsl:apply-templates select="$node">
                    <xsl:with-param name="depth" select="$depth"/>
                    <xsl:with-param name="space" select="$space"/>
                </xsl:apply-templates>
            </xsl:if>
            <xsl:call-template name="f:walk">
                <xsl:with-param name="node" select="$node/following-sibling::node()[1]"/>
                <xsl:with-param name="depth" select="$depth"/>
                <xsl:with-param name="break" select="$next-break"/>
                <xsl:with-param name="context" select="$type"/>
                <xsl:with-param name="space" select="$space"/>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>
    <xsl:template match="f:xmldecl">
        <xsl:param name="depth"/>
        <xsl:param name="space"/>
        <xsl:text>&lt;?xml</xsl:text>
        <xsl:if test="$xmldecl-version">
            <xsl:value-of select="concat(' version=&quot;', $xmldecl-version, '&quot;')"/>
        </xsl:if>
        <xsl:if test="$xmldecl-encoding">
            <xsl:value-of select="concat(' encoding=&quot;', $xmldecl-encoding, '&quot;')"/>
        </xsl:if>
        <xsl:if test="$xmldecl-standalone">
            <xsl:value-of select="concat(' standalone=&quot;', $xmldecl-standalone, '&quot;')"/>
        </xsl:if>
        <xsl:text>?&gt;</xsl:text>
    </xsl:template>
    <xsl:template match="f:doctype">
        <xsl:param name="depth"/>
        <xsl:param name="space"/>
        <xsl:text>&lt;!DOCTYPE </xsl:text>
        <xsl:value-of select="name($root/*)"/>
        <xsl:choose>
            <xsl:when test="$doctype-public">
                <xsl:text> PUBLIC</xsl:text>
            </xsl:when>
            <xsl:otherwise>
                <xsl:text> SYSTEM</xsl:text>
            </xsl:otherwise>
        </xsl:choose>
        <xsl:if test="$doctype-public">
            <xsl:value-of select="concat(' &quot;', $doctype-public, '&quot;')"/>
        </xsl:if>
        <xsl:if test="$doctype-system">
            <xsl:value-of select="concat(' &quot;', $doctype-system, '&quot;')"/>
        </xsl:if>
        <xsl:if test="$doctype-content">
            <xsl:value-of select="concat(' [', $doctype-content, ']')"/>
        </xsl:if>
        <xsl:text>&gt;</xsl:text>
    </xsl:template>
    <xsl:template match="f:root">
        <xsl:param name="depth"/>
        <xsl:param name="space"/>
        <xsl:call-template name="f:walk">
            <xsl:with-param name="node" select="$root/node()[1]"/>
            <xsl:with-param name="depth" select="$depth"/>
            <xsl:with-param name="break" select="0"/>
            <xsl:with-param name="context" select="&quot;block&quot;"/>
            <xsl:with-param name="space" select="$space"/>
            <xsl:with-param name="started" select="false()"/>
        </xsl:call-template>
    </xsl:template>
    <xsl:template match="*">
        <xsl:param name="depth"/>
        <xsl:param name="space"/>
        <xsl:variable name="inside">
            <xsl:apply-templates mode="f:break-inside" select="."/>
        </xsl:variable>
        <xsl:variable name="depth-delta">
            <xsl:apply-templates mode="f:indent" select="."/>
        </xsl:variable>
        <xsl:variable name="empty">
            <xsl:apply-templates mode="f:empty" select="."/>
        </xsl:variable>
        <xsl:variable name="new-space">
            <xsl:choose>
                <xsl:when test="$space = 'default'">
                    <xsl:apply-templates mode="f:space" select="."/>
                </xsl:when>
                <xsl:otherwise>preserve</xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="context">
            <xsl:call-template name="f:child-context"/>
        </xsl:variable>
        <xsl:apply-templates mode="f:begin-tag" select=".">
            <xsl:with-param name="empty" select="$empty"/>
            <xsl:with-param name="depth" select="$depth"/>
        </xsl:apply-templates>
        <xsl:call-template name="f:walk">
            <xsl:with-param name="node" select="node()[1]"/>
            <xsl:with-param name="depth" select="$depth + number($depth-delta)"/>
            <xsl:with-param name="break" select="$inside"/>
            <xsl:with-param name="context" select="$context"/>
            <xsl:with-param name="space" select="$new-space"/>
        </xsl:call-template>
        <xsl:if test="$empty = 'no'">
            <xsl:if test="$space = 'default' and not($context = 'inline')">
                <xsl:variable name="last" select="node()[not(text() and normalize-space() = '')][last()]"/>
                <xsl:call-template name="f:break">
                    <xsl:with-param name="former">
                        <xsl:apply-templates mode="f:break-outside" select="$last"/>
                    </xsl:with-param>
                    <xsl:with-param name="latter" select="$inside"/>
                </xsl:call-template>
                <xsl:call-template name="f:indent">
                    <xsl:with-param name="depth" select="$depth"/>
                </xsl:call-template>
            </xsl:if>
            <xsl:apply-templates mode="f:end-tag" select="."/>
        </xsl:if>
    </xsl:template>
    <xsl:template match="*" mode="f:begin-tag">
        <xsl:param name="node" select="."/>
        <xsl:param name="empty" select="'no'"/>
        <xsl:param name="depth"/>
        <xsl:text>&lt;</xsl:text>
        <xsl:value-of select="name($node)"/>
        <xsl:variable name="attr-align">
            <xsl:apply-templates mode="f:attr-align" select="$node"/>
        </xsl:variable>
        <xsl:variable name="ns" select="$node/../namespace::node()"/>
        <xsl:for-each select="namespace::node()">
            <xsl:variable name="name" select="local-name()"/>
            <xsl:variable name="same-ns" select="$ns[local-name() = $name]"/>
            <xsl:if test="$name != 'xml' and not($same-ns and $same-ns = .)">
                <xsl:call-template name="f:attr-sep">
                    <xsl:with-param name="attr-align" select="$attr-align"/>
                    <xsl:with-param name="depth" select="$depth"/>
                </xsl:call-template>
                <xsl:call-template name="f:xmlns"/>
            </xsl:if>
        </xsl:for-each>
        <xsl:for-each select="@*">
            <xsl:call-template name="f:attr-sep">
                <xsl:with-param name="attr-align" select="$attr-align"/>
                <xsl:with-param name="depth" select="$depth"/>
            </xsl:call-template>
            <xsl:call-template name="f:attribute"/>
        </xsl:for-each>
        <xsl:if test="$empty = &quot;yes&quot;">
            <xsl:text> /</xsl:text>
        </xsl:if>
        <xsl:text>&gt;</xsl:text>
    </xsl:template>
    <xsl:template match="f:comment" mode="f:begin-tag">
        <xsl:param name="node"/>
        <xsl:param name="empty"/>
        <xsl:param name="depth"/>
        <xsl:text>&lt;!--</xsl:text>
    </xsl:template>
    <xsl:template match="f:cdata" mode="f:begin-tag">
        <xsl:param name="node"/>
        <xsl:param name="empty"/>
        <xsl:param name="depth"/>
        <xsl:text>&lt;![CDATA[</xsl:text>
    </xsl:template>
    <xsl:template name="f:attr-sep">
        <xsl:param name="attr-align"/>
        <xsl:param name="depth"/>
        <xsl:choose>
            <xsl:when test="$attr-align = &quot;indent&quot;">
                <xsl:call-template name="f:do-break"/>
                <xsl:call-template name="f:indent">
                    <xsl:with-param name="depth" select="$depth + 1"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:text> </xsl:text>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="f:attribute">
        <xsl:param name="node" select="."/>
        <xsl:value-of select="name()"/>
        <xsl:text>="</xsl:text>
        <xsl:call-template name="f:escape">
            <xsl:with-param name="node" select="$node"/>
        </xsl:call-template>
        <xsl:text>"</xsl:text>
    </xsl:template>
    <xsl:template name="f:xmlns">
        <xsl:param name="node" select="."/>
        <xsl:variable name="name" select="local-name($node)"/>
        <xsl:value-of select="'xmlns'"/>
        <xsl:if test="$name != ''">
            <xsl:value-of select="concat(':', $name)"/>
        </xsl:if>
        <xsl:text>="</xsl:text>
        <xsl:call-template name="f:escape">
            <xsl:with-param name="node" select="$node"/>
        </xsl:call-template>
        <xsl:text>"</xsl:text>
    </xsl:template>
    <xsl:template match="*" mode="f:end-tag">
        <xsl:param name="node" select="."/>
        <xsl:text>&lt;/</xsl:text>
        <xsl:value-of select="name($node)"/>
        <xsl:text>&gt;</xsl:text>
    </xsl:template>
    <xsl:template match="f:comment" mode="f:end-tag">
        <xsl:param name="node" select="."/>
        <xsl:text>--&gt;</xsl:text>
    </xsl:template>
    <xsl:template match="f:cdata" mode="f:end-tag">
        <xsl:param name="node" select="."/>
        <xsl:text>]]&gt;</xsl:text>
    </xsl:template>
    <xsl:template match="text()">
        <xsl:param name="depth"/>
        <xsl:param name="space"/>
        <xsl:choose>
            <xsl:when test="$space = 'preserve'">
                <xsl:call-template name="f:escape"/>
            </xsl:when>
            <xsl:when test="not(normalize-space() = '')">
                <xsl:variable name="text" select="normalize-space(concat('a', ., 'a'))"/>
                <xsl:call-template name="f:escape">
                    <xsl:with-param name="node" select="substring($text, 2, string-length($text) - 2)"/>
                </xsl:call-template>
            </xsl:when>
        </xsl:choose>
    </xsl:template>
    <xsl:template match="comment()">
        <xsl:param name="depth"/>
        <xsl:param name="space"/>
        <xsl:text>&lt;!--</xsl:text>
        <xsl:value-of select="."/>
        <xsl:text>--&gt;</xsl:text>
    </xsl:template>
    <xsl:template match="processing-instruction()">
        <xsl:param name="depth"/>
        <xsl:param name="space"/>
        <xsl:text>&lt;?</xsl:text>
        <xsl:value-of select="local-name()"/>
        <xsl:value-of select="."/>
        <xsl:text>?&gt;</xsl:text>
    </xsl:template>
    <xsl:template name="f:child-context">
        <xsl:param name="node" select="."/>
        <xsl:variable name="ret">
            <xsl:for-each select="$node/node()">
                <xsl:variable name="display">
                    <xsl:apply-templates mode="f:display" select="."/>
                </xsl:variable>
                <xsl:if test="$display = 'block'">1</xsl:if>
            </xsl:for-each>
        </xsl:variable>
        <xsl:choose>
            <xsl:when test="string($ret)">block</xsl:when>
            <xsl:otherwise>inline</xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template match="/ | node()" mode="f:available">
        <xsl:param name="space"/>yes</xsl:template>
    <xsl:template match="f:xmldecl" mode="f:available" priprity="10">
        <xsl:param name="space"/>
        <xsl:if test="$xmldecl = 'yes'">yes</xsl:if>
    </xsl:template>
    <xsl:template match="f:doctype" mode="f:available" priprity="10">
        <xsl:param name="space"/>
        <xsl:if test="$doctype-public or $doctype-system">yes</xsl:if>
    </xsl:template>
    <xsl:template match="f:document/text()" mode="f:available" priprity="10">
        <xsl:param name="space"/>
    </xsl:template>
    <xsl:template match="text()" mode="f:available">
        <xsl:param name="space"/>
        <xsl:choose>
            <xsl:when test="$space = 'default' and normalize-space() = ''">no</xsl:when>
            <xsl:otherwise>yes</xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="f:escape">
        <xsl:param name="node" select="."/>
        <xsl:variable name="tmp1">
            <xsl:call-template name="f:gsub">
                <xsl:with-param name="text" select="$node"/>
                <xsl:with-param name="from" select="'&amp;'"/>
                <xsl:with-param name="to" select="'&amp;amp;'"/>
            </xsl:call-template>
        </xsl:variable>
        <xsl:variable name="tmp2">
            <xsl:call-template name="f:gsub">
                <xsl:with-param name="text" select="$tmp1"/>
                <xsl:with-param name="from" select="'&lt;'"/>
                <xsl:with-param name="to" select="'&amp;lt;'"/>
            </xsl:call-template>
        </xsl:variable>
        <xsl:variable name="tmp3">
            <xsl:call-template name="f:gsub">
                <xsl:with-param name="text" select="$tmp2"/>
                <xsl:with-param name="from" select="'&gt;'"/>
                <xsl:with-param name="to" select="'&amp;gt;'"/>
            </xsl:call-template>
        </xsl:variable>
        <xsl:call-template name="f:gsub">
            <xsl:with-param name="text" select="$tmp3"/>
            <xsl:with-param name="from" select="'&quot;'"/>
            <xsl:with-param name="to" select="'&amp;quot;'"/>
        </xsl:call-template>
    </xsl:template>
    <xsl:template name="f:gsub">
        <xsl:param name="text"/>
        <xsl:param name="from"/>
        <xsl:param name="to"/>
        <xsl:choose>
            <xsl:when test="contains($text, $from)">
                <xsl:value-of select="substring-before($text, $from)"/>
                <xsl:value-of select="$to"/>
                <xsl:call-template name="f:gsub">
                    <xsl:with-param name="text" select="substring-after($text, $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="$text"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="f:indent">
        <xsl:param name="depth"/>
        <xsl:if test="$depth &gt; 0">
            <xsl:value-of select="$indentstr"/>
            <xsl:call-template name="f:indent">
                <xsl:with-param name="depth" select="$depth - 1"/>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>
    <xsl:template name="f:break">
        <xsl:param name="former"/>
        <xsl:param name="latter"/>
        <xsl:variable name="n-former" select="number($former)"/>
        <xsl:variable name="n-latter" select="number($latter)"/>
        <xsl:if test="$debug">
            <xsl:value-of select="concat('[b:', $n-former, '/', $n-latter, ']')"/>
        </xsl:if>
        <xsl:choose>
            <xsl:when test="$n-former &gt; $n-latter">
                <xsl:call-template name="f:do-break">
                    <xsl:with-param name="count" select="$n-former"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="f:do-break">
                    <xsl:with-param name="count" select="$n-latter"/>
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="f:do-break">
        <xsl:param name="count" select="1"/>
        <xsl:if test="$count &gt; 0">
            <xsl:value-of select="$breakstr"/>
            <xsl:call-template name="f:do-break">
                <xsl:with-param name="count" select="$count - 1"/>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>
