Browse Source

Import the texml-related XSL files into this repository

This helps against build failures due to sourceforge being
unavailable.
hacx
Jonas Wielicki 5 years ago
parent
commit
b9a410551e
  1. 1
      Dockerfile
  2. 318
      texml-xsl/cmp.xsl
  3. 1447
      texml-xsl/date-time.xsl
  4. 90
      texml-xsl/example.xsl
  5. 789
      texml-xsl/markup.xsl
  6. 618
      texml-xsl/math.xsl
  7. 229
      texml-xsl/node.xsl
  8. 340
      texml-xsl/stdlib.xsl
  9. 1233
      texml-xsl/string.xsl
  10. 1
      texml-xsl/svg.xsl
  11. 580
      texml-xsl/uri.xsl
  12. 2
      xep2texml.xsl

1
Dockerfile

@ -10,6 +10,7 @@ COPY *.xml xep.* *.css *.xsl *.js *.xsl Makefile /src/ @@ -10,6 +10,7 @@ COPY *.xml xep.* *.css *.xsl *.js *.xsl Makefile /src/
COPY resources/*.pdf /src/resources/
COPY tools/*.py /src/tools/
COPY inbox/*.xml inbox/*.ent inbox/*.dtd /src/inbox/
COPY texml-xsl/*.xsl /src/texml-xsl/
WORKDIR /src
RUN OUTDIR=/var/www/html/extensions/ make -j$NCORES $TARGETS

318
texml-xsl/cmp.xsl

@ -0,0 +1,318 @@ @@ -0,0 +1,318 @@
<?xml version="1.0"?>
<xsl:stylesheet
version="1.0"
extension-element-prefixes="doc"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:doc="http://xsltsl.org/xsl/documentation/1.0"
xmlns:str="http://xsltsl.org/string"
xmlns:cmp="http://xsltsl.org/cmp"
exclude-result-prefixes="cmp str doc"
>
<doc:reference xmlns="">
<referenceinfo>
<releaseinfo role="meta">
$Id$
</releaseinfo>
<author>
<surname>Hummel</surname>
<firstname>Mark</firstname>
</author>
<copyright>
<year>2003</year>
<holder>Mark Hummel</holder>
</copyright>
</referenceinfo>
<title>XML Compare</title>
<partintro>
<section>
<title>Introduction</title>
<para>This module provides a template for comparing two xml documents. </para>
</section>
</partintro>
</doc:reference>
<doc:template name="cmp:diff">
<refpurpose>Compare</refpurpose>
<refdescription>
<para>Compare two xml documents and display differences. Two xml documents are defined to be the same if: They have the matching elements and attributes, and that the data in the elements also match. The comparison is order sensitive. </para>
<para>The element names from the documents at the current depth are compared, followed by their values, then any attribute names and values are compared. The process is applied then to the subtrees of the documents.</para>
<para>Notes: If there are leaf nodes in one nodeset which don't exist in the other, the value of those 'extra' elements won't appear as a difference.
</para>
</refdescription>
<refparameter>
<variablelist>
<varlistentry>
<term>ns1</term>
<term>ns2</term>
<listitem>
<para>The two nodesets which are to be compared. </para>
</listitem>
</varlistentry>
</variablelist>
</refparameter>
<refreturn>
<para>Returns the difference between the documents. </para>
<para>The format of the output is an xml document. A node is added to the result tree for every difference. The node contains the type of difference (e.g element name difference, attribute value difference, etc), the value in the first nodeset and the value in the second nodeset, and the parent node. The indentation level is the depth at which the difference was found relative to the first document. </para>
</refreturn>
</doc:template>
<!-- pass in a nodeset and compare. Is order sensitive. Output attribute, element and textual differences. -->
<xsl:template name="cmp:diff">
<xsl:param name="ns1"/>
<xsl:param name="ns2"/>
<!-- attribute compare -->
<!-- Optimisation attempt
Can probaby change this into one loop ie -
<xsl:for-each
i = position
if node1[i] = node2[i]...
-->
<!-- Need to check if there are two sets of attributes -->
<xsl:choose>
<xsl:when test='count($ns1/attribute::*) = count($ns2/attribute::*)'>
<xsl:for-each select="$ns1/attribute::*">
<xsl:variable name="name1" select="name()"/>
<xsl:variable name="value1" select="."/>
<xsl:variable name="i" select="position()"/>
<xsl:for-each select="$ns2/attribute::*">
<xsl:variable name="j" select="position()"/>
<xsl:variable name="name2" select="name()"/>
<xsl:variable name="value2" select="."/>
<xsl:if test="$i = $j">
<xsl:if test="$name1 != $name2">
<attributeNameDifference>
<parentElement><xsl:value-of select="name(..)"/></parentElement>
<before><xsl:value-of select="$name1"/></before>
<after><xsl:value-of select="$name2"/></after>
</attributeNameDifference>
</xsl:if>
<xsl:if test="$name1 = $name2 and $value1 != $value2">
<attributeValueDifference>
<parentElement><xsl:value-of select="name(..)"/></parentElement>
<before><xsl:value-of select="$value1"/></before>
<after><xsl:value-of select="$value2"/></after>
</attributeValueDifference>
</xsl:if>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<attributeNameDifference>
<parentElement>
<xsl:value-of select="name(..)"/>
</parentElement>
<before><xsl:value-of select='$ns1/attribute::*'/></before>
<after><xsl:value-of select='$ns2/attribute::*'/></after>
</attributeNameDifference>
</xsl:otherwise>
</xsl:choose>
<!-- Find element differences by comparing the element names from the same position in both documents. Iterate over all the nodes in the nodeset with the largest number of elements, so the extra elements will appear as differences. -->
<xsl:choose>
<!-- Define loop direction based on which tree has more nodes
FIXME: Replacing this with one for-each and a test for the case
of the second tree having more nodes would be more elegant
Solution: Add variable for direction and assign the 'larger' nodeset to that
variable. Then do one for-each.
FIXME: The solution is a bit too iterative. Make it more functional
-->
<xsl:when test="count($ns1) &gt; count($ns2)">
<xsl:for-each select="$ns1">
<xsl:variable name="i" select="position()"/>
<xsl:message>node[<xsl:value-of select='$i'/>]:
<xsl:value-of select='$ns1[$i]'/>
</xsl:message>
<!-- Element name compare -->
<xsl:if test="name($ns1[$i]) != name($ns2[$i])">
<elementNameDifference>
<parentElement><xsl:value-of select="name(..)"/></parentElement>
<before><xsl:value-of select="name($ns1[$i])"/></before>
<after><xsl:value-of select="name($ns2[$i])"/></after>
</elementNameDifference>
</xsl:if>
<!-- Element Value compare -->
<xsl:if test="count($ns1/*) = 0">
<xsl:if test="$ns1[$i] != $ns2[$i]">
<elementValueDifference>
<parentElement><xsl:value-of select="name(..)"/></parentElement>
<before><xsl:value-of select="$ns1[$i]"/></before>
<after><xsl:value-of select="$ns2[$i]"/></after>
</elementValueDifference>
</xsl:if>
</xsl:if>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="$ns2">
<xsl:variable name="i" select="position()"/>
<!-- Element Name compare -->
<xsl:if test="name($ns1[$i]) != name($ns2[$i])">
<elementNameDifference>
<parentElement><xsl:value-of select="name(..)"/></parentElement>
<before><xsl:value-of select="name($ns1[$i])"/></before>
<after><xsl:value-of select="name($ns2[$i])"/></after>
</elementNameDifference>
</xsl:if>
<!-- value compare -->
<xsl:if test="count($ns2/*) = 0">
<xsl:if test="$ns2[$i] != $ns1[$i]">
<elementValueDifference>
<parentElement><xsl:value-of select="name(..)"/></parentElement>
<after><xsl:value-of select="$ns2[$i]"/></after>
<before><xsl:value-of select="$ns1[$i]"/></before>
</elementValueDifference>
</xsl:if>
</xsl:if>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
<!-- stop processing when leaf node is reached. -->
<xsl:if test="count($ns1/*) &gt; 0 and count($ns2/*) &gt; 0">
<xsl:call-template name="cmp:diff">
<xsl:with-param name="ns1" select="$ns1/*"/>
<xsl:with-param name="ns2" select="$ns2/*"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<!-- Return false if the two nodesets are not identical
-->
<xsl:template name="cmp:cmp">
<xsl:param name="ns1"/>
<xsl:param name="ns2"/>
<xsl:param name="depth"/>
<xsl:choose>
<xsl:when test='count($ns1) != count($ns2)'>
<xsl:value-of select='"countDiff"'/>
</xsl:when>
<xsl:when test='count($ns1/attribute::*) != count($ns2/attribute::*)'>
<xsl:value-of select='"countDiff"'/>
</xsl:when>
<xsl:when test='$ns1 and $ns2'>
<xsl:variable name='result'>
<xsl:call-template name='cmp:cmp'>
<xsl:with-param name='ns1' select='$ns1/*'/>
<xsl:with-param name='ns2' select='$ns2/*'/>
<xsl:with-param name='depth' select='$depth+1'/>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test='$result = "countDiff"'>
<xsl:value-of select='$result'/>
</xsl:when>
<xsl:when test='$result = "textDiff"'>
<xsl:value-of select='$result'/>
</xsl:when>
<xsl:when test='$result = ""'>
<xsl:variable name='keyText1' select='name($ns1)'/>
<xsl:variable name='keyText2' select='name($ns2)'/>
<xsl:choose>
<!-- Check if the text of the nodesets are the same and the attributes-->
<xsl:when test='$ns1 = $ns2 and $keyText1 = $keyText2'>
<!-- Check the attribute names are the same -->
<!-- Number of attributes being different is caught higher up -->
<xsl:if test='count($ns1/attribute::*)'>
<xsl:for-each select='$ns1/attribute::*'>
<xsl:variable name='i' select='position()'/>
<xsl:variable name='name1' select='name(.)'/>
<xsl:variable name='value1' select='.'/>
<xsl:for-each select='$ns2/attribute::*'>
<xsl:variable name='j' select='position()'/>
<xsl:variable name='name2' select='name(.)'/>
<xsl:variable name='value2' select='.'/>
<xsl:if test='$i = $j and ($name1 != $name2 or
$value1 != $value2)'>
<xsl:value-of select='"textDiff"'/>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</xsl:if>
<!--
<xsl:variable name='diffResult'>
<xsl:call-template name='cmp:diff'>
<xsl:with-param name='ns1' select='$ns1'/>
<xsl:with-param name='ns2' select='$ns2'/>
</xsl:call-template>
</xsl:variable>
<xsl:if test='not($diffResult = "")'>
<xsl:value-of select='"textDiff"'/>
</xsl:if>
-->
</xsl:when>
<xsl:otherwise>
<xsl:value-of select='"textDiff"'/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:when>
<xsl:when test='$ns1 and not($ns2)'>
<xsl:value-of select='"structDiff"'/>
</xsl:when>
<xsl:when test='$ns2 and not($ns1)'>
<xsl:value-of select='"structDiff"'/>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

1447
texml-xsl/date-time.xsl

File diff suppressed because it is too large Load Diff

90
texml-xsl/example.xsl

@ -0,0 +1,90 @@ @@ -0,0 +1,90 @@
<?xml version="1.0"?>
<xsl:stylesheet
version="1.0"
extension-element-prefixes="doc"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:doc="http://xsltsl.org/xsl/documentation/1.0"
xmlns:eg="http://xsltsl.org/example"
>
<doc:reference xmlns="">
<referenceinfo>
<releaseinfo role="meta">
$Id$
</releaseinfo>
<author>
<surname>Ball</surname>
<firstname>Steve</firstname>
</author>
<copyright>
<year>2001</year>
<holder>Steve Ball</holder>
</copyright>
</referenceinfo>
<title>Example Stylesheet</title>
<partintro>
<section>
<title>Introduction</title>
<para>This module provides a template for adding stylesheet modules to the XSLT Standard Library.</para>
<para>To add a new module to the library, follow these easy steps:</para>
<orderedlist>
<listitem>
<para>Copy this file and replace its contents with the new module templates and documentation.</para>
</listitem>
<listitem>
<para>Copy the corresponding test file in the <filename>test</filename> directory. Replace its contents with tests for the new module.</para>
</listitem>
<listitem>
<para>Add an include element in the <filename>stdlib.xsl</filename> stylesheet.</para>
</listitem>
<listitem>
<para>Add an entry in the <filename>test/test.xml</filename> file.</para>
</listitem>
<listitem>
<para>Add entries in the <filename>test/test.xsl</filename> stylesheet.</para>
</listitem>
<listitem>
<para>Add an entry in the <filename>doc/build.xml</filename> file.</para>
</listitem>
</orderedlist>
<para>The <filename>example.xsl</filename> stylesheet provides a more extensive example.</para>
</section>
</partintro>
</doc:reference>
<doc:template name="eg:example" xmlns="">
<refpurpose>Template Example</refpurpose>
<refdescription>
<para>Provides a template for writing templates. Replace this paragraph with a description of your template</para>
</refdescription>
<refparameter>
<variablelist>
<varlistentry>
<term>text</term>
<listitem>
<para>The example string</para>
</listitem>
</varlistentry>
</variablelist>
</refparameter>
<refreturn>
<para>Returns nothing.</para>
</refreturn>
</doc:template>
<xsl:template name="eg:example">
<xsl:param name="text"/>
</xsl:template>
</xsl:stylesheet>

789
texml-xsl/markup.xsl

@ -0,0 +1,789 @@ @@ -0,0 +1,789 @@
<xsl:stylesheet version='1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
xmlns:doc='http://xsltsl.org/xsl/documentation/1.0'
xmlns:markup='http://xsltsl.org/markup'
xmlns:str='http://xsltsl.org/string'
extension-element-prefixes='doc markup str'>
<doc:reference xmlns=''>
<referenceinfo>
<releaseinfo role="meta">
$Id$
</releaseinfo>
<author>
<surname>Ball</surname>
<firstname>Steve</firstname>
</author>
<copyright>
<year>2003</year>
<year>2001</year>
<holder>Steve Ball</holder>
</copyright>
</referenceinfo>
<title>XML Markup Templates</title>
<partintro>
<section>
<title>Introduction</title>
<para>This stylesheet module provides functions for generating literal XML markup.</para>
</section>
</partintro>
</doc:reference>
<doc:template name="markup:xml-declaration" xmlns="">
<refpurpose>Create an XML Declaration</refpurpose>
<refdescription>
<para>This template returns an XML Declaration. Although the XSLT standard provides control over the generation of the XML Declaration, this template may be useful in circumstances where the values must be computed at runtime.</para>
</refdescription>
<refparameter>
<variablelist>
<varlistentry>
<term>version</term>
<listitem>
<para>Version number.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>standalone</term>
<listitem>
<para>Standalone indication. Must be value "yes" or "no".</para>
</listitem>
</varlistentry>
<varlistentry>
<term>encoding</term>
<listitem>
<para>Character encoding.</para>
</listitem>
</varlistentry>
</variablelist>
</refparameter>
<refreturn>
<para>Returns an XML Declaration as a string.</para>
</refreturn>
</doc:template>
<xsl:template name='markup:xml-declaration'>
<xsl:param name='version' select="'1.0'"/>
<xsl:param name='standalone'/>
<xsl:param name='encoding'/>
<xsl:text disable-output-escaping='yes'>&lt;?xml version="</xsl:text>
<xsl:copy-of select="$version"/>
<xsl:text>"</xsl:text>
<xsl:choose>
<xsl:when test="string-length($standalone) = 0"/>
<xsl:when test='$standalone = "yes" or $standalone = "no"'>
<xsl:text> standalone="</xsl:text>
<xsl:copy-of select="$standalone"/>
<xsl:text>"</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">invalid value "<xsl:value-of select="$standalone"/>" for standalone attribute</xsl:message>
</xsl:otherwise>
</xsl:choose>
<xsl:if test='string-length($encoding) &gt; 0'>
<xsl:text> encoding="</xsl:text>
<xsl:copy-of select='$encoding'/>
<xsl:text>"</xsl:text>
</xsl:if>
<xsl:text disable-output-escaping='yes'>?&gt;
</xsl:text>
</xsl:template>
<doc:template name="markup:doctype-declaration" xmlns="">
<refpurpose>Create a Document Type Declaration</refpurpose>
<refdescription>
<para>This template returns a Document Type Declaration. Although the XSLT standard provides control over the generation of a Document Type Declaration, this template may be useful in circumstances where the values for the identifiers or the internal subset must be computed at runtime.</para>
</refdescription>
<refparameter>
<variablelist>
<varlistentry>
<term>docel</term>
<listitem>
<para>The name of the document element.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>publicid</term>
<listitem>
<para>The public identifier for the external DTD subset.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>systemid</term>
<listitem>
<para>The system identifier for the external DTD subset.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>internaldtd</term>
<listitem>
<para>The internal DTD subset.</para>
</listitem>
</varlistentry>
</variablelist>
</refparameter>
<refreturn>
<para>Returns a Document Type Declaration as a string.</para>
</refreturn>
</doc:template>
<xsl:template name='markup:doctype-declaration'>
<xsl:param name='docel'/>
<xsl:param name='publicid'/>
<xsl:param name='systemid'/>
<xsl:param name='internaldtd'/>
<xsl:if test='string-length($docel) = 0'>
<xsl:message terminate='yes'>No document element specified</xsl:message>
</xsl:if>
<xsl:text disable-output-escaping='yes'>&lt;!DOCTYPE </xsl:text>
<xsl:copy-of select="$docel"/>
<xsl:call-template name='markup:external-identifier'>
<xsl:with-param name='publicid' select='$publicid'/>
<xsl:with-param name='systemid' select='$systemid'/>
<xsl:with-param name='leading-space' select='true()'/>
</xsl:call-template>
<xsl:if test='string-length($internaldtd) &gt; 0'>
<xsl:text> [</xsl:text>
<xsl:copy-of select='$internaldtd'/>
<xsl:text>]</xsl:text>
</xsl:if>
<xsl:text disable-output-escaping='yes'>&gt;
</xsl:text>
</xsl:template>
<doc:template name="markup:element-declaration" xmlns="">
<refpurpose>Create an Element Declaration</refpurpose>
<refdescription>
<para>This template returns an element declaration..</para>
</refdescription>
<refparameter>
<variablelist>
<varlistentry>
<term>type</term>
<listitem>
<para>The element type.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>content-spec</term>
<listitem>
<para>The content specification.</para>
</listitem>
</varlistentry>
</variablelist>
</refparameter>
<refreturn>
<para>Returns an element declaration as a string.</para>
</refreturn>
</doc:template>
<xsl:template name='markup:element-declaration'>
<xsl:param name='type'/>
<xsl:param name='content-spec' select="'ANY'"/>
<xsl:if test='string-length($type) = 0'>
<xsl:message terminate='yes'>element type must be specified</xsl:message>
</xsl:if>
<xsl:if test='string-length($content-spec) = 0'>
<xsl:message terminate='yes'>content specification must be specified</xsl:message>
</xsl:if>
<xsl:text disable-output-escaping='yes'>&lt;!ELEMENT </xsl:text>
<xsl:copy-of select='$type'/>
<xsl:text> </xsl:text>
<xsl:copy-of select='$content-spec'/>
<xsl:text disable-output-escaping='yes'>&gt;</xsl:text>
</xsl:template>
<doc:template name="markup:attlist-declaration" xmlns="">
<refpurpose>Create an Attribute List Declaration</refpurpose>
<refdescription>
<para>This template returns an attribute list declaration.</para>
</refdescription>
<refparameter>
<variablelist>
<varlistentry>
<term>type</term>
<listitem>
<para>The element type.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>attr-defns</term>
<listitem>
<para>Attribute definitions.</para>
</listitem>
</varlistentry>
</variablelist>
</refparameter>
<refreturn>
<para>Returns an attribute list declaration as a string.</para>
</refreturn>
</doc:template>
<xsl:template name='markup:attlist-declaration'>
<xsl:param name='type'/>
<xsl:param name='attr-defns'/>
<xsl:if test='string-length($type) = 0'>
<xsl:message terminate='yes'>element type must be specified</xsl:message>
</xsl:if>
<xsl:text disable-output-escaping='yes'>&lt;!ATTLIST </xsl:text>
<xsl:copy-of select='$type'/>
<xsl:text> </xsl:text>
<xsl:copy-of select='$attr-defns'/>
<xsl:text disable-output-escaping='yes'>&gt;</xsl:text>
</xsl:template>
<doc:template name="markup:attribute-definition" xmlns="">
<refpurpose>Create an Attribute Definition</refpurpose>
<refdescription>
<para>This template returns an attribute definition.</para>
</refdescription>
<refparameter>
<variablelist>
<varlistentry>
<term>name</term>
<listitem>
<para>The attribute name.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>type</term>
<listitem>
<para>The attribute type.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>default</term>
<listitem>
<para>The attribute default.</para>
</listitem>
</varlistentry>
</variablelist>
</refparameter>
<refreturn>
<para>Returns an attribute definition as a string.</para>
</refreturn>
</doc:template>
<xsl:template name='markup:attribute-definition'>
<xsl:param name='name'/>
<xsl:param name='type'/>
<xsl:param name='default'/>
<xsl:if test='string-length($name) = 0'>
<xsl:message terminate='yes'>attribute name must be specified</xsl:message>
</xsl:if>
<xsl:if test='string-length($type) = 0'>
<xsl:message terminate='yes'>attribute type must be specified</xsl:message>
</xsl:if>
<xsl:if test='string-length($default) = 0'>
<xsl:message terminate='yes'>attribute default must be specified</xsl:message>
</xsl:if>
<xsl:text> </xsl:text>
<xsl:copy-of select='$name'/>
<xsl:text> </xsl:text>
<xsl:copy-of select='$type'/>
<xsl:text> </xsl:text>
<xsl:copy-of select='$default'/>
</xsl:template>
<doc:template name="markup:entity-declaration" xmlns="">
<refpurpose>Create an Entity Declaration</refpurpose>
<refdescription>
<para>This template returns an entity declaration.</para>
<para>If the 'text' parameter is given a value, then an internal entity is created. If either the 'publicid' or 'systemid' parameters are given a value then an external entity is created. It is an error for the 'text' parameter to have value as well as the 'publicid', 'systemid' or 'notation' parameters.</para>
</refdescription>
<refparameter>
<variablelist>
<varlistentry>
<term>name</term>
<listitem>
<para>The entity name.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>parameter</term>
<listitem>
<para>Boolean value to determine whether a parameter entity is created. Default is 'false()'.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>text</term>
<listitem>
<para>The replacement text. Must be a string.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>nodes</term>
<listitem>
<para>The replacement text as a nodeset. The nodeset is formatted as XML using the as-xml template. If both text and nodes are specified then nodes takes precedence.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>publicid</term>
<listitem>
<para>The public identifier for an external entity.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>systemid</term>
<listitem>
<para>The system identifier for an external entity.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>notation</term>
<listitem>
<para>The notation for an external entity.</para>
</listitem>
</varlistentry>
</variablelist>
</refparameter>
<refreturn>
<para>Returns an entity declaration as a string.</para>
</refreturn>
</doc:template>
<xsl:template name='markup:entity-declaration'>
<xsl:param name='name'/>
<xsl:param name='parameter' select='false()'/>
<xsl:param name='text'/>
<xsl:param name='nodes'/>
<xsl:param name='publicid'/>
<xsl:param name='systemid'/>
<xsl:param name='notation'/>
<xsl:if test='string-length($name) = 0'>
<xsl:message terminate='yes'>entity name must be specified</xsl:message>
</xsl:if>
<xsl:if test='string-length($text) &gt; 0 and
(string-length($publicid) &gt; 0 or
string-length($systemid) &gt; 0 or
string-length($notation) &gt; 0)'>
<xsl:message terminate='yes'>both replacement text and external identifier specified</xsl:message>
</xsl:if>
<xsl:text disable-output-escaping='yes'>&lt;!ENTITY </xsl:text>
<xsl:copy-of select='$name'/>
<xsl:text> </xsl:text>
<xsl:if test="$parameter">
<xsl:text>% </xsl:text>
</xsl:if>
<xsl:choose>
<xsl:when test="$nodes">
<xsl:call-template name='markup:quote-value'>
<xsl:with-param name='value'>
<xsl:call-template name="markup:as-xml">
<xsl:with-param name="nodes" select="$nodes"/>
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:when test='$text'>
<xsl:call-template name='markup:quote-value'>
<xsl:with-param name='value' select='$text'/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name='markup:external-identifier'>
<xsl:with-param name='publicid' select='$publicid'/>
<xsl:with-param name='systemid' select='$systemid'/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
<xsl:if test='$notation'>
<xsl:text> NDATA "</xsl:text>
<xsl:copy-of select='$notation'/>
<xsl:text>"</xsl:text>
</xsl:if>
<xsl:text disable-output-escaping='yes'>&gt;</xsl:text>
</xsl:template>
<doc:template name="markup:quote-value" xmlns="">
<refpurpose>Quote an Attribute Value</refpurpose>
<refdescription>
<para>This template returns a quoted value.</para>
</refdescription>
<refparameter>
<variablelist>
<varlistentry>
<term>value</term>
<listitem>
<para>The value to quote.</para>
</listitem>
</varlistentry>
</variablelist>
</refparameter>
<refreturn>
<para>Returns a quote value as a string.</para>
</refreturn>
</doc:template>
<xsl:template name='markup:quote-value'>
<xsl:param name='value'/>
<xsl:variable name="quoted">
<xsl:call-template name='markup:quote-value-aux'>
<xsl:with-param name='value' select='$value'/>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains($value, '&lt;')">
<xsl:call-template name='str:subst'>
<xsl:with-param name='text' select='$quoted'/>
<xsl:with-param name='replace'>&lt;</xsl:with-param>
<xsl:with-param name='with'>
<xsl:text disable-output-escaping='yes'>&amp;lt;</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select='$quoted'/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name='markup:quote-value-aux'>
<xsl:param name='value'/>
<!-- Quoting hell! -->
<xsl:variable name="quot">&quot;</xsl:variable>
<xsl:variable name="apos">&apos;</xsl:variable>
<xsl:choose>
<xsl:when test='contains($value, $quot) and contains($value, $apos)'>
<xsl:text>"</xsl:text>
<xsl:call-template name='str:subst'>
<xsl:with-param name='text' select='$value'/>
<xsl:with-param name='replace'>"</xsl:with-param>
<xsl:with-param name='with'>
<xsl:text disable-output-escaping='yes'>&amp;quot;</xsl:text>
</xsl:with-param>
</xsl:call-template>
<xsl:text>"</xsl:text>
</xsl:when>
<xsl:when test='contains($value, $quot)'>
<xsl:text>'</xsl:text>
<xsl:value-of select='$value'/>
<xsl:text>'</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>"</xsl:text>
<xsl:value-of select='$value'/>
<xsl:text>"</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<doc:template name="markup:external-identifier" xmlns="">
<refpurpose>Create an External Identifier</refpurpose>
<refdescription>
<para>This template returns an external identifier.</para>
</refdescription>
<refparameter>
<variablelist>
<varlistentry>
<term>publicid</term>
<listitem>
<para>The public identifier.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>systemid</term>
<listitem>
<para>The system identifier.</para>
</listitem>
</varlistentry>
</variablelist>
</refparameter>
<refreturn>
<para>Returns an external identifier as a string.</para>
</refreturn>
</doc:template>
<xsl:template name='markup:external-identifier'>
<xsl:param name='publicid'/>
<xsl:param name='systemid'/>
<xsl:param name='leading-space' select='false()'/>
<xsl:choose>
<xsl:when test='string-length($publicid) &gt; 0'>
<xsl:if test='$leading-space'>
<xsl:text> </xsl:text>
</xsl:if>
<xsl:text disable-output-escaping='yes'>PUBLIC "</xsl:text>
<xsl:value-of select='$publicid' disable-output-escaping='yes'/>
<xsl:text disable-output-escaping='yes'>"</xsl:text>
<xsl:if test='string-length($systemid) &gt; 0'>
<xsl:text disable-output-escaping='yes'> "</xsl:text>
<xsl:value-of select='$systemid' disable-output-escaping='yes'/>
<xsl:text disable-output-escaping='yes'>"</xsl:text>
</xsl:if>
</xsl:when>
<xsl:when test="string-length($systemid) &gt; 0">
<xsl:if test='$leading-space'>
<xsl:text> </xsl:text>
</xsl:if>
<xsl:text disable-output-escaping='yes'>SYSTEM "</xsl:text>
<xsl:value-of select='$systemid' disable-output-escaping='yes'/>
<xsl:text disable-output-escaping='yes'>"</xsl:text>
</xsl:when>
</xsl:choose>
</xsl:template>
<doc:template name="markup:entity-reference" xmlns="">
<refpurpose>Create an Entity Reference</refpurpose>
<refdescription>
<para>This template returns an entity reference.</para>
</refdescription>
<refparameter>
<variablelist>
<varlistentry>
<term>name</term>
<listitem>
<para>The name of the entity.</para>
</listitem>
</varlistentry>
</variablelist>
</refparameter>
<refreturn>
<para>Returns an entity reference as a string.</para>
</refreturn>
</doc:template>
<xsl:template name='markup:entity-reference'>
<xsl:param name='name'/>
<xsl:text disable-output-escaping='yes'>&amp;</xsl:text>
<xsl:value-of select='$name'/>
<xsl:text>;</xsl:text>
</xsl:template>
<doc:template name="markup:notation-declaration" xmlns="">
<refpurpose>Create a Notation Declaration</refpurpose>
<refdescription>
<para>This template returns a notation declaration.</para>
</refdescription>
<refparameter>
<variablelist>
<varlistentry>
<term>name</term>
<listitem>
<para>The notation name.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>publicid</term>
<listitem>
<para>The public identifier for the notation.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>systemid</term>
<listitem>
<para>The system identifier for the notation.</para>
</listitem>
</varlistentry>
</variablelist>
</refparameter>
<refreturn>
<para>Returns a notation declaration as a string.</para>
</refreturn>
</doc:template>
<xsl:template name='markup:notation-declaration'>
<xsl:param name='name'/>
<xsl:param name='publicid'/>
<xsl:param name='systemid'/>
<xsl:if test='string-length($name) = 0'>
<xsl:message terminate='yes'>notation name must be specified</xsl:message>
</xsl:if>
<xsl:if test='string-length($publicid) = 0 and string-length($systemid) = 0'>
<xsl:message terminate='yes'>external identifier must be specified</xsl:message>
</xsl:if>
<xsl:text disable-output-escaping='yes'>&lt;!NOTATION </xsl:text>
<xsl:copy-of select='$name'/>
<xsl:call-template name='markup:external-identifier'>
<xsl:with-param name='publicid' select='$publicid'/>
<xsl:with-param name='systemid' select='$systemid'/>
<xsl:with-param name='leading-space' select='true()'/>
</xsl:call-template>
<xsl:text disable-output-escaping='yes'>&gt;</xsl:text>
</xsl:template>
<doc:template name="markup:cdata-section" xmlns="">
<refpurpose>Create a CDATA Section</refpurpose>
<refdescription>
<para>This template returns a CDATA Section. The XSLT specification provides a mechanism for instructing the XSL processor to output character data in a CDATA section for certain elements, but this template may be useful in those circumstances where not all instances of an element are to have their content placed in a CDATA section.</para>
</refdescription>
<refparameter>
<variablelist>
<varlistentry>
<term>text</term>
<listitem>
<para>The content of the CDATA section.</para>
</listitem>
</varlistentry>
</variablelist>
</refparameter>
<refreturn>
<para>Returns a CDATA section as a string.</para>
</refreturn>
</doc:template>
<xsl:template name='markup:cdata-section'>
<xsl:param name='text'/>
<xsl:if test="contains($text, ']]&gt;')">
<xsl:message terminate="yes">CDATA section contains "]]&gt;"</xsl:message>
</xsl:if>
<xsl:text disable-output-escaping='yes'>&lt;![CDATA[</xsl:text>
<xsl:copy-of select='$text'/>
<xsl:text disable-output-escaping='yes'>]]&gt;</xsl:text>
</xsl:template>
<doc:template name="markup:as-xml" xmlns="">
<refpurpose>Format Nodeset As XML Markup</refpurpose>
<refdescription>
<para>This template returns XML markup. Each node in the given nodeset is converted to its equivalent XML markup.</para>
<para>BUG: This version may not adequately handle XML Namespaces.</para>
</refdescription>
<refparameter>
<variablelist>
<varlistentry>
<term>nodes</term>
<listitem>
<para>Nodeset to format as XML.</para>
</listitem>
</varlistentry>
</variablelist>
</refparameter>
<refreturn>
<para>Returns XML markup.</para>
</refreturn>
</doc:template>
<xsl:template name='markup:as-xml'>
<xsl:param name='nodes'/>
<xsl:if test="$nodes">
<xsl:choose>
<xsl:when test="$nodes[1]/self::*">
<xsl:text disable-output-escaping='yes'>&lt;</xsl:text>
<xsl:value-of select="name($nodes[1])"/>
<xsl:for-each select="$nodes[1]/@*">
<xsl:text> </xsl:text>
<xsl:value-of select="name()"/>
<xsl:text>=</xsl:text>
<xsl:call-template name='markup:quote-value'>
<xsl:with-param name='value' select='.'/>
</xsl:call-template>
</xsl:for-each>
<xsl:choose>
<xsl:when test='$nodes[1]/node()'>
<xsl:text disable-output-escaping='yes'>&gt;</xsl:text>
<xsl:call-template name='markup:as-xml'>
<xsl:with-param name='nodes' select='$nodes[1]/node()'/>
</xsl:call-template>
<xsl:text disable-output-escaping='yes'>&lt;/</xsl:text>
<xsl:value-of select="name($nodes[1])"/>
<xsl:text disable-output-escaping='yes'>&gt;</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text disable-output-escaping='yes'>/&gt;</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$nodes[1]/self::text()">
<xsl:value-of select="$nodes[1]"/>
</xsl:when>
<xsl:when test="$nodes[1]/self::comment()">
<xsl:text disable-output-escaping='yes'>&lt;!--</xsl:text>
<xsl:value-of select="$nodes[1]"/>
<xsl:text disable-output-escaping='yes'>--&gt;</xsl:text>
</xsl:when>
<xsl:when test="$nodes[1]/self::processing-instruction()">
<xsl:text disable-output-escaping='yes'>&lt;?</xsl:text>
<xsl:value-of select="name($nodes[1])"/>
<xsl:text> </xsl:text>
<xsl:value-of select="$nodes[1]"/>
<xsl:text disable-output-escaping='yes'>?&gt;</xsl:text>
</xsl:when>
<xsl:when test="not($nodes[1]/parent::*)"/> <!-- root node -->
<xsl:when test="count($nodes[1] | $nodes[1]/../namespace::*) = count($nodes[1]/../namespace::*)"/> <!-- namespace node -->
<xsl:when test="count($nodes[1] | $nodes[1]/../@*) = count($nodes[1]/../@*)"/> <!-- attribute node -->
</xsl:choose>
<xsl:call-template name="markup:as-xml">
<xsl:with-param name="nodes" select="$nodes[position() &gt; 1]"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>

618
texml-xsl/math.xsl

@ -0,0 +1,618 @@ @@ -0,0 +1,618 @@
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:doc="http://xsltsl.org/xsl/documentation/1.0"
xmlns:math="http://xsltsl.org/math"
exclude-result-prefixes="doc math">
<doc:reference xmlns="">
<referenceinfo>
<releaseinfo role="meta">
$Id$
</releaseinfo>
<author>
<surname>Ball</surname>
<firstname>Steve</firstname>
</author>
<copyright>
<year>2004</year>
<year>2002</year>
<holder>Steve Ball</holder>
</copyright>
</referenceinfo>
<title>Math Module</title>
<partintro>
<section>
<title>Introduction</title>
<para>This module provides mathematical functions.</para>
</section>
</partintro>
</doc:reference>
<doc:template name="math:power" xmlns="">
<refpurpose>Power</refpurpose>
<refdescription>
<para>Raises a number to a power.</para>
</refdescription>
<refparameter>
<variablelist>
<varlistentry>
<term>base</term>
<listitem>
<para>The base number. Must be a number.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>power</term>
<listitem>
<para>The power to raise the number to. Must be an integer.</para>
</listitem>
</varlistentry>
</variablelist>
</refparameter>
<refreturn>
<para>Returns base multiplied by itself power times. If the base or power are not numbers or if the power is fractional then an empty string is returned.</para>
</refreturn>
</doc:template>
<xsl:template name="math:power">
<xsl:param name="base"/>
<xsl:param name="power"/>
<xsl:choose>
<xsl:when test='$power = "0" and $base = "0"'>
<xsl:text>1</xsl:text>
</xsl:when>
<xsl:when test='$power = "0" and number($base)'>
<xsl:text>1</xsl:text>
</xsl:when>
<xsl:when test='$power = "0" and not(number($base))'/>
<xsl:when test='$base = "0" and number($power)'>
<xsl:text>0</xsl:text>
</xsl:when>
<xsl:when test='not(number($base)) or not(number($power))'/>
<xsl:when test='floor(number($power)) != number($power)'/>
<xsl:when test='number($power) &lt; 0'>
<xsl:variable name='x'>
<xsl:call-template name='math:power'>
<xsl:with-param name='base' select='$base'/>
<xsl:with-param name='power' select='-1 * $power'/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select='1 div $x'/>
</xsl:when>
<xsl:when test='number($power) = 1'>
<xsl:value-of select='$base'/>
</xsl:when>
<xsl:when test='number($power) &gt; 0'>
<xsl:variable name='x'>
<xsl:call-template name='math:power'>
<xsl:with-param name='base' select='$base'/>
<xsl:with-param name='power' select='$power - 1'/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select='$base * $x'/>
</xsl:when>
<xsl:otherwise/>
</xsl:choose>
</xsl:template>
<doc:template name="math:cvt-hex-decimal" xmlns="">
<refpurpose>Conversion</refpurpose>
<refdescription>
<para>Converts a hexidecimal value to a decimal value.</para>
</refdescription>
<refparameter>
<variablelist>
<varlistentry>
<term>value</term>
<listitem>
<para>The hexidecimal number. Must be a number in hexidecimal format.</para>
</listitem>
</varlistentry>
</variablelist>
</refparameter>
<refreturn>
<para>Returns the value as a decimal string. If the value is not a number then a NaN value is returned.</para>
</refreturn>
</doc:template>
<xsl:template name="math:cvt-hex-decimal">
<xsl:param name="value"/>
<xsl:choose>
<xsl:when test='$value = ""'/>
<xsl:when test='string-length($value) = 1'>
<xsl:call-template name='math:cvt-hex-decimal-digit'>
<xsl:with-param name='digit' select='$value'/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:variable name='first-digit'>
<xsl:call-template name='math:cvt-hex-decimal-digit'>
<xsl:with-param name='digit' select='substring($value, 1, 1)'/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name='remainder'>
<xsl:call-template name='math:cvt-hex-decimal'>
<xsl:with-param name='value' select='substring($value, 2)'/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select='$first-digit * 16 + $remainder'/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name='math:cvt-hex-decimal-digit'>
<xsl:param name='digit' select='0'/>
<xsl:choose>
<xsl:when test='$digit &lt;= 9'>
<xsl:value-of select='$digit'/>
</xsl:when>
<xsl:when test='$digit = "a" or $digit = "A"'>10</xsl:when>
<xsl:when test='$digit = "b" or $digit = "B"'>11</xsl:when>
<xsl:when test='$digit = "c" or $digit = "C"'>12</xsl:when>
<xsl:when test='$digit = "d" or $digit = "D"'>13</xsl:when>
<xsl:when test='$digit = "e" or $digit = "E"'>14</xsl:when>
<xsl:when test='$digit = "f" or $digit = "F"'>15</xsl:when>
</xsl:choose>
</xsl:template>
<doc:template name="math:ordinal" xmlns="">
<refpurpose>Ordinal number</refpurpose>
<refdescription>
<para>Gives the ordinal number of a given counting number. For example, 1 becomes "1st".</para>
</refdescription>
<refparameter>
<variablelist>
<varlistentry>
<term>number</term>
<listitem>
<para>An integer number.</para>
</listitem>
</varlistentry>
</variablelist>
</refparameter>
<refreturn>
<para>Returns the number with an ordinal suffix.</para>
</refreturn>
</doc:template>
<xsl:template name="math:ordinal">
<xsl:param name="number"/>
<xsl:choose>
<xsl:when test='$number &lt; 0'/>
<xsl:otherwise>
<xsl:value-of select='$number'/>
<xsl:choose>
<xsl:when test='$number = 11 or $number = 12 or $number = 13'>th</xsl:when>
<xsl:when test='$number mod 10 = 1'>st</xsl:when>
<xsl:when test='$number mod 10 = 2'>nd</xsl:when>
<xsl:when test='$number mod 10 = 3'>rd</xsl:when>
<xsl:otherwise>th</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<doc:template name="math:ordinal-as-word" xmlns="">
<refpurpose>Returns an ordinal number</refpurpose>
<refdescription>
<para>This template returns the ordinal number for a given counting number as a word. For example "first" for 1.</para>
<para>Only handles numbers less than 10000000 (ten million).</para>
</refdescription>
<refparameter>
<variablelist>
<varlistentry>
<term>number</term>
<listitem>
<para>The counting number.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>conjunctive</term>
<listitem>
<para>Whether to add the word "and" to the result, for example "one hundred and first" rather than "one hundred first". Default is "yes".</para>
</listitem>
</varlistentry>
</variablelist>
</refparameter>
<refreturn>
<para>Returns the ordinal number as a string.</para>
</refreturn>
</doc:template>
<xsl:template name="math:ordinal-as-word">
<xsl:param name="number" select="0"/>
<xsl:param name='conjunctive' select='"yes"'/>
<xsl:param name='preceding' select='0'/>
<xsl:choose>
<xsl:when test='$preceding = 1 and $number = 0'/>
<xsl:when test='$number = 0'>zeroth</xsl:when>
<xsl:when test="$number &lt; 1 or $number != floor($number)"/>
<xsl:when test='$number = 1'>
<xsl:if test='$preceding = 1'> and </xsl:if>
<xsl:text>first</xsl:text>
</xsl:when>
<xsl:when test='$number = 2'>
<xsl:if test='$preceding = 1'> and </xsl:if>
<xsl:text>second</xsl:text>
</xsl:when>
<xsl:when test='$number = 3'>
<xsl:if test='$preceding = 1'> and </xsl:if>
<xsl:text>third</xsl:text>
</xsl:when>
<xsl:when test='$number = 4'>
<xsl:if test='$preceding = 1'> and </xsl:if>
<xsl:text>fourth</xsl:text>
</xsl:when>
<xsl:when test='$number = 5'>
<xsl:if test='$preceding = 1'> and </xsl:if>
<xsl:text>fifth</xsl:text>
</xsl:when>
<xsl:when test='$number = 6'>
<xsl:if test='$preceding = 1'> and </xsl:if>
<xsl:text>sixth</xsl:text>
</xsl:when>
<xsl:when test='$number = 7'>
<xsl:if test='$preceding = 1'> and </xsl:if>
<xsl:text>seventh</xsl:text>
</xsl:when>
<xsl:when test='$number = 8'>
<xsl:if test='$preceding = 1'> and </xsl:if>
<xsl:text>eighth</xsl:text>
</xsl:when>
<xsl:when test='$number = 9'>
<xsl:if test='$preceding = 1'> and </xsl:if>
<xsl:text>ninth</xsl:text>
</xsl:when>
<xsl:when test='$number = 10'>
<xsl:if test='$preceding = 1'> and </xsl:if>
<xsl:text>tenth</xsl:text>
</xsl:when>
<xsl:when test='$number = 11'>
<xsl:if test='$preceding = 1'> and </xsl:if>
<xsl:text>eleventh</xsl:text>
</xsl:when>
<xsl:when test='$number = 12'>
<xsl:if test='$preceding = 1'> and </xsl:if>
<xsl:text>twelveth</xsl:text>
</xsl:when>
<xsl:when test='$number = 13'>
<xsl:if test='$preceding = 1'> and </xsl:if>
<xsl:text>thirteenth</xsl:text>
</xsl:when>
<xsl:when test='$number = 14'>
<xsl:if test='$preceding = 1'> and </xsl:if>
<xsl:text>fourteenth</xsl:text>
</xsl:when>
<xsl:when test='$number = 15'>
<xsl:if test='$preceding = 1'> and </xsl:if>
<xsl:text>fifteenth</xsl:text>
</xsl:when>
<xsl:when test='$number = 16'>
<xsl:if test='$preceding = 1'> and </xsl:if>
<xsl:text>sixteenth</xsl:text>
</xsl:when>
<xsl:when test='$number = 17'>
<xsl:if test='$preceding = 1'> and </xsl:if>
<xsl:text>seventeenth</xsl:text>
</xsl:when>
<xsl:when test='$number = 18'>
<xsl:if test='$preceding = 1'> and </xsl:if>