ArkML/Codec implementations

Converting to HTML
Converting to HTML makes it easy to display ArkML on HTML based renderers, such as an embedded Webkit or MozEmbed.

XSLT 1.0
XSLT is a universal XML transformation language, and should be used in all programming environments in favor of language specific procedural transformations.

No XSLT 2.0 features are required for this transformation.

'''Note: XSLT only operates on XML. You must first convert the SGML to XML''' - which is generally a simple process. For command line environments see the "osx" utility.

                <xsl:param name="str" select="."/> <xsl:choose> <xsl:when test="not(contains($str, '&amp;#xA;'))">  </xsl:when> <xsl:otherwise> <xsl:value-of select="substring-before($str, '&amp;#xA;')"/>

<xsl:call-template name="br"> <xsl:with-param name="str" select="substring-after($str, '&amp;#xA;')"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>

Python 3 using LXML and BeautifulSoup
You will need two PyPI packages: lxml and beautifulsoup4.

First we need to create the XSLT transformer to avoid creating it every time we parse ArkML. "xsltstr" is a string (or bytes) that contain the XSLT code above.

from lxml import etree transform = etree.XSLT(etree.fromstring(xsltstr))

Now we parse the ArkML data. "arkmlstr" is a string (or bytes) containing the input ArkML data. The input must be wrapped in span elements as XSLT only operates on XML documents (APIs that let you apply XSLT transformations on XML fragments secretly add a nothing document around the fragment, but in python this is done explicitly). The output ("htmlspan") will be an LXML object containing an HTML span element. This code usually does parse SGML by automatically choosing any available SGML parser installed in the Python installation.

from lxml.html import soupparser htmlspan = transform(soupparser.fromstring(b" " + arkmlstr.replace(b'&', b'&amp;#x26;') + b" ", features="xml")[0])

And then you can convert it back to a bytes / string:

print(b''.join([etree.tostring(c) for c in htmlspan.getroot.iterdescendants]))

ArkML/Implémentations Codec