<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="#self" type="text/xsl" title="Generate text/plain JS+CSS Entitags"?>
<?xml-stylesheet href="#self" type="text/xml" title="Generate text/plain JS+CSS Entitags"?>
<!DOCTYPE xsl:stylesheet
          [
          <!ATTLIST xsl:stylesheet id ID #REQUIRED>
          <!ENTITY cr "&#xD;"><!ENTITY lf "&#xA;"><!ENTITY br "&lf;">
          <!ENTITY nl "<xsl:text xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>&br;</xsl:text>">
          ]>
<!--  ================================================  -->
<!--  ================================================  -->
<!--  ================================================ 

      internal subset entities fail with IE5 + MSXML3

      ================================================  -->
<!--  ================================================  -->
<!--  ================================================  -->

<xsl:stylesheet version="1.0" id="self"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:ent="urn:entitags:entity-as-empty-element-tag"
                >
<xsl:output indent="no"
            method="html"
            encoding="utf-8"
            media-type="text/html"
            doctype-public="-//W3C//DTD XHTML 1.1//EN"
            doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
            omit-xml-declaration="no"
            />
<xsl:preserve-space elements="pre" />
<xsl:template match="xsl:stylesheet" />

<xsl:param name="NN" select="''" />     <!-- generateNN  -->

<xsl:variable name="NofEntitags" select="count(document('entitags.xml')//ent:el)" />

<xsl:template match="/">
    <html>
    <head><title>ML &#xB7; XSLT Entitags to JS/CSS-Source</title>
    <style type="text/css">
        <xsl:text>
            pre  { font: normal 9pt/13pt 'andale mono', 'lucida console', 'lucida sans typewriter', 'ocr a extended', 'courier new', courier, monospace; }
        </xsl:text>
    </style>
    </head>
    <body><pre>
    <xsl:choose>
        <xsl:when test="$NN='JS'">
            <xsl:call-template name="generateJSarray" />
            <xsl:call-template name="generateJSobjlit" />
        </xsl:when>
        <xsl:when test="$NN='CSS2'">
            <xsl:call-template name="generateCSS2" />
        </xsl:when>
        <xsl:when test="$NN='CSS3'">
            <xsl:call-template name="generateCSS3" />
        </xsl:when>
        <xsl:otherwise>
            <xsl:call-template name="generateJSobjlit" />
            <xsl:call-template name="generateCSS3" />
        </xsl:otherwise>
    </xsl:choose>
	</pre>
    </body>
    </html>
</xsl:template>

<!--  ================================================  -->
<!--  ================================================  -->
<!--  ================================================  -->

<xsl:template name="generateCSS3">
    <xsl:text>&#xD;&#xA;</xsl:text>
    <xsl:text>/*   *************************************************** &#xD;&#xA;</xsl:text>
    <xsl:text> *   CSS-3 generated/transformed from entitagX-HTpre.xml &#xD;&#xA;</xsl:text>
    <xsl:text> *   XML v</xsl:text><xsl:value-of select="system-property('xsl:version')" /> <xsl:text>&#xD;&#xA;</xsl:text>
    <xsl:text> *   XSLTransformed by &#xD;&#xA;</xsl:text>
    <xsl:text> *   </xsl:text><xsl:value-of select="system-property('xsl:vendor')" /> <xsl:text>&#xD;&#xA;</xsl:text>
    <xsl:text> *   </xsl:text><xsl:value-of select="system-property('xsl:vendor-url')" /> <xsl:text>&#xD;&#xA;</xsl:text>
    <xsl:text> */  </xsl:text>
    <xsl:text>&#xD;&#xA;</xsl:text>
    <xsl:text>&#xD;&#xA;@namespace ent uri(urn:entitags:entity-as-empty-element-tag); </xsl:text>
    <xsl:text>&#xD;&#xA;ent|*[unicode]::after { content: attr(unicode); }  /* DOC-local or DTD-default */&#xD;&#xA;&#xD;&#xA;</xsl:text>
    <xsl:for-each select="document('entitags.xml')//ent:el">
        <xsl:text>ent|</xsl:text>
        <xsl:value-of select="@tagname" />
        <xsl:text>::after { content: &quot;</xsl:text>
        <xsl:value-of select="@csscode" />
        <xsl:text>&quot;; }</xsl:text>
        <xsl:text>  /*</xsl:text><xsl:value-of select="following::comment()" /><xsl:text>*/ &#xD;&#xA;</xsl:text>
    </xsl:for-each>
    <xsl:text>&#xD;&#xA;</xsl:text>
</xsl:template>

<xsl:template name="generateCSS2">
    <xsl:text>&#xD;&#xA;</xsl:text>
    <xsl:text>/*   *************************************************** &#xD;&#xA;</xsl:text>
    <xsl:text> *   CSS-2 generated/transformed from entitagX-HTpre.xml &#xD;&#xA;</xsl:text>
    <xsl:text> *   XML v</xsl:text><xsl:value-of select="system-property('xsl:version')" /> <xsl:text>&#xD;&#xA;</xsl:text>
    <xsl:text> *   XSLTransformed by &#xD;&#xA;</xsl:text>
    <xsl:text> *   </xsl:text><xsl:value-of select="system-property('xsl:vendor')" /> <xsl:text>&#xD;&#xA;</xsl:text>
    <xsl:text> *   </xsl:text><xsl:value-of select="system-property('xsl:vendor-url')" /> <xsl:text>&#xD;&#xA;</xsl:text>
    <xsl:text> */  </xsl:text>
    <xsl:text>&#xD;&#xA;</xsl:text>
    <xsl:text>&#xD;&#xA;*[unicode]:after { content: attr(unicode); } &#xD;&#xA;&#xD;&#xA;</xsl:text>
    <xsl:for-each select="document('entitags.xml')//ent:el">
        <xsl:value-of select="@tagname" />
        <xsl:text>:after { content : &quot;</xsl:text>
        <xsl:value-of select="@csscode" />
        <xsl:text>&quot;; }</xsl:text>
        <xsl:text>  /*</xsl:text><xsl:value-of select="following::comment()" /><xsl:text>*/ &#xD;&#xA;</xsl:text>
    </xsl:for-each>
    <xsl:text>&#xD;&#xA;</xsl:text>
</xsl:template>

<xsl:template name="bslashESC">
    <xsl:param name="str" />
    <xsl:param name="esc" />
    <xsl:choose>
        <xsl:when test="contains($str,$esc)">
            <xsl:value-of select="substring-before($str,$esc)" /><xsl:text>\</xsl:text><xsl:value-of select="$esc" />
            <xsl:call-template name="bslashESC">
                <xsl:with-param name="str" select="substring-after($str,$esc)" />
                <xsl:with-param name="esc" select="$esc" />
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$str" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template name="generateJSarray">
    <xsl:text>&#xD;&#xA;</xsl:text>
    <xsl:text>/*   ****************************************************** &#xD;&#xA;</xsl:text>
    <xsl:text> *   JS-Array generated/transformed from entitagX-HTpre.xml &#xD;&#xA;</xsl:text>
    <xsl:text> *   XML v</xsl:text><xsl:value-of select="system-property('xsl:version')" /> <xsl:text>&#xD;&#xA;</xsl:text>
    <xsl:text> *   XSLTransformed by &#xD;&#xA;</xsl:text>
    <xsl:text> *   </xsl:text><xsl:value-of select="system-property('xsl:vendor')" /> <xsl:text>&#xD;&#xA;</xsl:text>
    <xsl:text> *   </xsl:text><xsl:value-of select="system-property('xsl:vendor-url')" /> <xsl:text>&#xD;&#xA;</xsl:text>
    <xsl:text> */  </xsl:text>
    <xsl:text>&#xD;&#xA;</xsl:text>
    <xsl:text>&#xD;&#xA;var ent = new Array(</xsl:text><xsl:value-of select="$NofEntitags" /><xsl:text>);   //  Array for Entitags-Transformation &#xD;&#xA;&#xD;&#xA;</xsl:text>
    <xsl:for-each select="document('entitags.xml')//ent:el">
        <xsl:text>ent[&quot;</xsl:text>
        <xsl:value-of select="@tagname" />
        <xsl:text>&quot;]=&quot;</xsl:text>
        <xsl:choose>
            <xsl:when test="string-length(@texcode)=1">
                <xsl:text>\u</xsl:text><xsl:value-of select="substring(@csscode,4)" />
            </xsl:when>
            <xsl:otherwise>
                <xsl:variable name="texcode">
                    <xsl:call-template name="bslashESC">
                        <xsl:with-param name="str" select="@texcode" />
                        <xsl:with-param name="esc" select="'\'" />
                    </xsl:call-template>
                </xsl:variable>
                <xsl:call-template name="bslashESC">
                    <xsl:with-param name="str" select="$texcode" />
                    <xsl:with-param name="esc" select="'&quot;'" />
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
        <xsl:text>&quot;; &#xD;&#xA;</xsl:text>
    </xsl:for-each>
    <xsl:text>&#xD;&#xA;</xsl:text>
</xsl:template>

<xsl:template name="generateJSobjlit">
    <xsl:text>&#xD;&#xA;</xsl:text>
    <xsl:text>/*   **************************************************************** &#xD;&#xA;</xsl:text>
    <xsl:text> *   JS-Object-Literals generated/transformed from entitagX-HTpre.xml &#xD;&#xA;</xsl:text>
    <xsl:text> *   XML v</xsl:text><xsl:value-of select="system-property('xsl:version')" /> <xsl:text>&#xD;&#xA;</xsl:text>
    <xsl:text> *   XSLTransformed by &#xD;&#xA;</xsl:text>
    <xsl:text> *   </xsl:text><xsl:value-of select="system-property('xsl:vendor')" /> <xsl:text>&#xD;&#xA;</xsl:text>
    <xsl:text> *   </xsl:text><xsl:value-of select="system-property('xsl:vendor-url')" /> <xsl:text>&#xD;&#xA;</xsl:text>
    <xsl:text> */  </xsl:text>
    <xsl:text>&#xD;&#xA;</xsl:text>
    <xsl:text>&#xD;&#xA;               //  USAGE: ent.isoname OR ent[&quot;isoname&quot;] OR ent[el.localName]</xsl:text>
    <xsl:text>&#xD;&#xA;               //         if (&quot;isoname&quot; in ent) {}; OR if (el.localName in ent) {};</xsl:text>
    <xsl:text>&#xD;&#xA;               //         for (var n in ent) {};</xsl:text>
    <xsl:text>&#xD;&#xA;const ent = {  //  </xsl:text><xsl:value-of select="$NofEntitags" /><xsl:text>  Object-Literals for Entitags-Transformation&#xD;&#xA;&#xD;&#xA;</xsl:text>
    <xsl:for-each select="document('entitags.xml')//ent:el">
        <xsl:value-of select="@tagname" />
        <xsl:text>:&quot;</xsl:text>
        <xsl:choose>
            <xsl:when test="string-length(@texcode)=1">
                <xsl:text>\u</xsl:text><xsl:value-of select="substring(@csscode,4)" />
            </xsl:when>
            <xsl:otherwise>
                <xsl:variable name="texcode">
                    <xsl:call-template name="bslashESC">
                        <xsl:with-param name="str" select="@texcode" />
                        <xsl:with-param name="esc" select="'\'" />
                    </xsl:call-template>
                </xsl:variable>
                <xsl:call-template name="bslashESC">
                    <xsl:with-param name="str" select="$texcode" />
                    <xsl:with-param name="esc" select="'&quot;'" />
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
        <xsl:text>&quot;</xsl:text>
		<xsl:if test="not(position()=$NofEntitags)"><xsl:text>, &#xD;&#xA;</xsl:text></xsl:if>
    </xsl:for-each>
    <xsl:text>  };  //  end of ent &#xD;&#xA;&#xD;&#xA;</xsl:text>
</xsl:template>


<!--  ================================================  -->
<!--  ================================================  -->
<!--  ================================================  -->

</xsl:stylesheet>

<!--  ================================================  -->
<!--  EOF                                               -->
<!--  ================================================  -->