Browse Source

* Added XSLT standard library (XSLTSL).

* Added a “Deny from all” directive in /tools so that this directory is
  not accessable to the public.  We need to exclude this directory from
  being uploaded in the build script in the future.
* /events/events.xsl should now take us of the standard library for
  retrieving month names. 

svn path=/branches/test/; revision=13906
tags/stw2018
ato 10 years ago
parent
commit
8742bfd44b

+ 37
- 40
events/events.xsl View File

@@ -1,7 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dt="http://xsltsl.org/date-time">

<xsl:include href="../tools/xsltsl/date-time.xsl" />
<xsl:output method="xml" encoding="UTF-8" indent="yes" />

<!-- Basically, copy everything -->
@@ -16,47 +19,41 @@
<xsl:param name="header" />

<!-- Create variables -->
<xsl:variable name="start"><xsl:value-of select="@start" /></xsl:variable>
<xsl:variable name="end"><xsl:value-of select="@end" /></xsl:variable>
<xsl:variable name="link"><xsl:value-of select="link" /></xsl:variable>
<xsl:variable name="page"><xsl:value-of select="page" /></xsl:variable>

<xsl:variable name="start_day"><xsl:value-of select="substring($start,9,2)" /></xsl:variable>
<xsl:variable name="end_day"><xsl:value-of select="substring($end,9,2)" /></xsl:variable>

<xsl:variable name="tmp_start_month"><xsl:value-of select="substring($start,6,2)" /></xsl:variable>

<xsl:choose>
<xsl:when test="$tmp_start_month = '01'"><xsl:variable name="start_month"><xsl:value-of select="/html/text [@id = 'months/01']" /></xsl:variable></xsl:when>
<xsl:when test="$tmp_start_month = '02'"><xsl:variable name="start_month"><xsl:value-of select="/html/text [@id = 'months/02']" /></xsl:variable></xsl:when>
<xsl:when test="$tmp_start_month = '03'"><xsl:variable name="start_month"><xsl:value-of select="/html/text [@id = 'months/03']" /></xsl:variable></xsl:when>
<xsl:when test="$tmp_start_month = '04'"><xsl:variable name="start_month"><xsl:value-of select="/html/text [@id = 'months/04']" /></xsl:variable></xsl:when>
<xsl:when test="$tmp_start_month = '05'"><xsl:variable name="start_month"><xsl:value-of select="/html/text [@id = 'months/05']" /></xsl:variable></xsl:when>
<xsl:when test="$tmp_start_month = '06'"><xsl:variable name="start_month"><xsl:value-of select="/html/text [@id = 'months/06']" /></xsl:variable></xsl:when>
<xsl:when test="$tmp_start_month = '07'"><xsl:variable name="start_month"><xsl:value-of select="/html/text [@id = 'months/07']" /></xsl:variable></xsl:when>
<xsl:when test="$tmp_start_month = '08'"><xsl:variable name="start_month"><xsl:value-of select="/html/text [@id = 'months/08']" /></xsl:variable></xsl:when>
<xsl:when test="$tmp_start_month = '09'"><xsl:variable name="start_month"><xsl:value-of select="/html/text [@id = 'months/09']" /></xsl:variable></xsl:when>
<xsl:when test="$tmp_start_month = '10'"><xsl:variable name="start_month"><xsl:value-of select="/html/text [@id = 'months/10']" /></xsl:variable></xsl:when>
<xsl:when test="$tmp_start_month = '11'"><xsl:variable name="start_month"><xsl:value-of select="/html/text [@id = 'months/11']" /></xsl:variable></xsl:when>
<xsl:when test="$tmp_start_month = '12'"><xsl:variable name="start_month"><xsl:value-of select="/html/text [@id = 'months/12']" /></xsl:variable></xsl:when>
</xsl:choose>
<xsl:variable name="start">
<xsl:value-of select="@start" />
</xsl:variable>
<xsl:variable name="tmp_end_month"><xsl:value-of select="substring($end,6,2)" /></xsl:variable>
<xsl:variable name="start_day">
<xsl:value-of select="substring($start,9,2)" />
</xsl:variable>
<xsl:choose>
<xsl:when test="$tmp_end_month = '01'"><xsl:variable name="end_month"><xsl:value-of select="/html/text [@id = 'months/01']" /></xsl:variable></xsl:when>
<xsl:when test="$tmp_end_month = '02'"><xsl:variable name="end_month"><xsl:value-of select="/html/text [@id = 'months/02']" /></xsl:variable></xsl:when>
<xsl:when test="$tmp_end_month = '03'"><xsl:variable name="end_month"><xsl:value-of select="/html/text [@id = 'months/03']" /></xsl:variable></xsl:when>
<xsl:when test="$tmp_end_month = '04'"><xsl:variable name="end_month"><xsl:value-of select="/html/text [@id = 'months/04']" /></xsl:variable></xsl:when>
<xsl:when test="$tmp_end_month = '05'"><xsl:variable name="end_month"><xsl:value-of select="/html/text [@id = 'months/05']" /></xsl:variable></xsl:when>
<xsl:when test="$tmp_end_month = '06'"><xsl:variable name="end_month"><xsl:value-of select="/html/text [@id = 'months/06']" /></xsl:variable></xsl:when>
<xsl:when test="$tmp_end_month = '07'"><xsl:variable name="end_month"><xsl:value-of select="/html/text [@id = 'months/07']" /></xsl:variable></xsl:when>
<xsl:when test="$tmp_end_month = '08'"><xsl:variable name="end_month"><xsl:value-of select="/html/text [@id = 'months/08']" /></xsl:variable></xsl:when>
<xsl:when test="$tmp_end_month = '09'"><xsl:variable name="end_month"><xsl:value-of select="/html/text [@id = 'months/09']" /></xsl:variable></xsl:when>
<xsl:when test="$tmp_end_month = '10'"><xsl:variable name="end_month"><xsl:value-of select="/html/text [@id = 'months/10']" /></xsl:variable></xsl:when>
<xsl:when test="$tmp_end_month = '11'"><xsl:variable name="end_month"><xsl:value-of select="/html/text [@id = 'months/11']" /></xsl:variable></xsl:when>
<xsl:when test="$tmp_end_month = '12'"><xsl:variable name="end_month"><xsl:value-of select="/html/text [@id = 'months/12']" /></xsl:variable></xsl:when>
</xsl:choose>
<xsl:variable name="start_month">
<xsl:call-template name="dt:get-month-name-abbreviation">
<xsl:with-param name="month" select="substring($start,6,2)" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="end">
<xsl:value-of select="@end" />
</xsl:variable>
<xsl:variable name="end_day">
<xsl:value-of select="substring($end,9,2)" />
</xsl:variable>
<xsl:variable name="end_month">
<xsl:call-template name="dt:get-month-name-abbreviation">
<xsl:with-param name="month" select="substring($end,6,2)" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="link">
<xsl:value-of select="link" />
</xsl:variable>
<xsl:variable name="page">
<xsl:value-of select="page" />
</xsl:variable>

<!-- Before the first event, include the header -->
<xsl:if test="position() = 1">

+ 2
- 0
tools/.htaccess View File

@@ -0,0 +1,2 @@
Deny From All


+ 77
- 0
tools/xsltsl/ANNOUNCE View File

@@ -0,0 +1,77 @@
XSLT Standard Library

Version 1.2.1

The XSLT Standard Library is a collection of commonly-used
templates written purely in XSLT.

This release features:
* New SVG and comparison modules
* New templates (functions) in string, date-time and math modules.
* Various bug fixes and patches (see ChangeLog).

Anyone who has useful XSLT templates that feels that they
may be of use to a wide range of XSLT developers and
applications is invited to submit their templates for
inclusion in the library.

USAGE
=====

Method 1: Unpack the distribution (see below) and
include or import either the main stylesheet, stdlib.xsl,
into your own stylesheet or include/import individual stylesheets
as needed.

Method 2: Import or include the main stylesheet, or an
individual stylesheet, directly from the project website.
Main stylesheet: http://xsltsl.sourceforge.net/xsl/stdlib.xsl

See http://xsltsl.sourceforge.net/ for further instructions.

xsltsl uses XML Namespaces, so there's no need to worry about
clashing template names.

DOWNLOAD
========

Gzipped tarball: http://prdownloads.sourceforge.net/xsltsl/xsltsl-1.2.1.tar.gz
Zip archive: http://prdownloads.sourceforge.net/xsltsl/xsltsl-1.2.1.zip

GETTING INVOLVED
================

xsltsl is a SourceForge project. Contributions are welcome.
Any contributed code must use the LGPL license to be accepted
into the library.

Project Page: http://sourceforge.net/projects/xsltsl/

Project Web Page: http://xsltsl.sourceforge.net/

There are three mailing lists for the project:

xsltsl-users@lists.sourceforge.net
Discussion of the use of xsltsl.
xsltsl-devel@lists.sourceforge.net
Discussion of the development of xsltsl.
xsltsl-announce@lists.sourceforge.net
Project announcements.

Bug reports are most welcome, and these may be submitted via the project Web page.

LICENSE
=======

xsltsl is LGPL'd.

ACKNOWLEDGEMENTS
================

Project Manager: Steve Ball, Zveno. Steve.Ball@zveno.com
Developers: Stuart Hungerford. Stuart.Hungerford@anu.edu.au
Leo Monus.
Jason Diamond. jason@injektilo.org
Reinout van Rees. R.vanRees@ct.tudelft.nl
Mark Hummel, Zveno. Mark.Hummel@zveno.com


+ 183
- 0
tools/xsltsl/ChangeLog View File

@@ -0,0 +1,183 @@
*** VERSION: Version 1.2.1 released

2004-10-10 Steve Ball <Steve.Ball@zveno.com>
* date-time.xsl (get-month-number): Fixed bug #1043193
* test/test.xml, test/compare.test.xsl, doc/build.xml: Added comparison module.

*** VERSION: Version 1.2 released

2004-10-08 Steve Ball <Steve.Ball@zveno.com>
* math.xsl: Added math:ordinal, math:ordinal-as-word, math:number-as-word.
* date-time.xsl: Added dt:calculate-last-day-of-month (patch #1015758).
* date-time.xsl: Added dt:get-xsd-datetime-* templates.

2004-08-11 Steve Ball <Steve.Ball@zveno.com>
* string.xsl (str:substring-after-at, str:substring-before-at): Fixed bug where 'chars' parameter was misnamed.

2004-05-06 Steve Ball <Steve.Ball@zveno.com>
* date-time.xsl (dt:format-date-time): Added %Q and %q to give A.M./P.M. indicator with periods.

2004-02-06 Steve Ball <Steve.Ball@zveno.com>
* date-time.xsl (dt:format-date-time): INCOMPATIBLE CHANGE.
Added %P for uppercase am/pm indicator, changed %p to give lowercase am/pm indicator.
Added %e to give day-of-month without leading zero, %i for hour without leading zero, %n for month without leading zero.

2003-03-10 Steve Ball <Steve.Ball@zveno.com>
* string.xsl (str:subst): Added disable-output-escaping parameter.
* markup.xsl: Added disable-output-escaping to internal DTD.

2003-01-30 Steve Ball <Steve.Ball@zveno.com>
* math.xsl: Added math:cvt-hex-decimal template.

2003-01-13 Reinout van Rees <reinout@vanrees.org>

* markup.xsl:
markup:cdata-section missed the '!' in the <![CDATA[. BTW, the testfile
doesn't contain a test for this template. But the magic of testing for
<![CDATA[ is a bit too deep for me.

2002-08-02 Steve Ball <steve@localhost>

* node.xsl: Added node:copy template.

2002-06-25 Steve Ball <steve@localhost>

* string.xsl: Changed substring-after-chars parameter to 'chars' to match function synposis.

2002-06-23 Steve Ball <steve@localhost>

* stdlib.xsl, svg.xsl: Added SVG module.

2002-06-18 Steve Ball <steve@localhost>

* string.xsl: Added str:justify template to string module.

2002-02-28 balls <balls@xml>

* doc/example.html, doc/makehtml.xsl, doc/markup.html,
doc/node.html, doc/stdlib.html, doc/string.html,
doc/test/test.html, doc/uri.html, test/math.test.xsl,
test/test.xml, test/test.xsl, ANNOUNCE, ChangeLog, doc/ChangeLog,
doc/allxsl2jref.xsl, doc/date-time.html,
doc/docbook-extensions.html, math.xsl, stdlib.xsl:
Added math module.

2002-01-16 Reinout van Rees <reinout@vanrees.org>

* test/string.test.xsl: small error fixed

2002-01-11 injektilo <injektilo@xml>

* test/uri.test.xsl, uri.xsl, ChangeLog:
Added 'document' parameter to resolve-uri for full compliance with RFC2396.

2002-01-11 Jason Diamond <jason@injektilo.org>
* uri.xsl, test/uri.test.xsl:
Added 'document' parameter to resolve-uri. This optionally
specifies the current document URI in case it's
different than the current base URI.

2002-01-08 Jason Diamond <jason@injektilo.org>
* uri.xsl, test/uri.test.xsl:
Fixed bug in resolve-uri where it was normalizing absolute
paths. All tests from RFC2396 now pass.

2002-01-08 Jason Diamond <jason@injektilo.org>
* uri.xsl:
Removed dependancy on string module by writing URI-specific
helper templates.

2002-01-07 Steve Ball <Steve.Ball@zveno.com>

* VERSION: Version 1.1 released.


2002-01-05 Jason Diamond <jason@injektilo.org>
* date-time.xsl, test/date-time.test.xsl:
Implemented the %I and %p codes in format-date-time
courtesy of Hans Stoop <hstoop@opentext.com>.

2002-01-05 Steve Ball <Steve.Ball@zveno.com>
* markup.xsl, test/markup.test.xsl
Added new markup module.

2002-01-05 Jason Diamond <jason@injektilo.org>
* test/gentest.test.xsl, test/results.xsl, test/results.css:
Tests results now use an XML format that can be styled for
viewing in a browser.

2002-01-04 Jason Diamond <jason@injektilo.org>
* string.xsl, test/string.test.xsl:
Added substring-before-last template.
* uri.xsl, test/uri.test.xsl:
Added resolve-uri template.

2001-12-16 Steve Ball <Steve.Ball@zveno.com>
* node.xsl:
Applied patch #447412 to handle all node types.

2001-12-14 Reinout van Rees <R.vanRees@ct.tudelft.nl>
* string.xsl:
Added improved unicode upper/lowercase handling.
Added to-camelcase template for converting strings into one
UpperCamelCase or lowerCamelCase word.

2001-12-14 Steve Ball <Steve.Ball@zveno.com>
* string.xsl:
Renamed variables. Some XSLT processors don't cope
with QNames for variable names.

2001-11-03 Steve Ball <Steve.Ball@zveno.com>

* VERSION: Version 1.0 released.

2001-11-03 Steve Ball <Steve.Ball@zveno.com>
* Added doc/allxsl2jref.xsl, doc/makehtml.xsl,
doc/build.xml. These automate building the documentation
set.

2001-11-01 Steve Ball <Steve Ball@zveno.com>
* Added string-match, character-first to string.xsl

2001-10-29 Leo Monus <Leo.Monus@zveno.com>
* Added substring-after-at, insert-at, backward
to string.xsl.

2001-??-?? Steve Ball <Steve.Ball@zveno.com>

* VERSION: Version 0.3 released.

2001-05-09 Steve Ball <Steve.Ball@zveno.com>
* XML Namespace root changed from
http://xsltsl.sourceforge.net to
http://xsltsl.org
* Added test/gentest.xsl to generate test.xsl

2001-??-?? Steve Ball <Steve.Ball@zveno.com>

* VERSION: Version 0.2 released.

2001-04-13 Jason Diamond <jason@injektilo.org>

* Added uri.xsl
* Added uri.test.xsl

2001-04-07 Steve Ball <Steve.Ball@zveno.com>

* string.xsl, test/string.test.xsl
Added str:substring-before-first, 'all' parameter to capitalise.
capitalise by default capitalises all words in a string.
* Changed documentation namespace URI to http://xsltsl.sourceforge.net/xsl/documentation/1.0
since new elements have been added.
* Added documentation for DocBook extensions.
* Added example stylesheet module.
* Added node.xsl

2001-04-04 Steve Ball <Steve.Ball@zveno.com>

* VERSION: Version 0.1 released.

2002-02-21 Steve Ball <Steve.Ball@zveno.com>
* math.xsl, test/math.xsl, stdlib.xsl, test/test.xml
Added math module.

+ 33
- 0
tools/xsltsl/RELNOTES View File

@@ -0,0 +1,33 @@

*** Version 1.2.1 2004-10-10

Bugs fixed: 1043193

*** Version 1.2 2004-10-08

New modules: svg
Bugs fixed: #502351, numerous unreported bugs
Patches applied: #1015758

*** Version 1.1 2002-01-07

New modules: markup
Bugs fixed: None open
Patches applied: #447412, #482472

Notes:

1. Variables in the string module have been renamed to
eliminate the use of QNames, which is problematic in
some XSLT processors. All variables have been prefixed
by 'xsltsl-'. User stylesheets should avoid naming
variables or parameters with the same prefix.

2. Some templates in the markup module check their
parameters for error conditions and terminate the
entire stylesheet processing if an error condition is
found. In this version this behaviour is not
configurable.

=======================================================


+ 318
- 0
tools/xsltsl/cmp.xsl View File

@@ -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: cmp.xsl,v 1.4 2004/10/10 06:18:57 balls Exp $
</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
- 0
tools/xsltsl/date-time.xsl
File diff suppressed because it is too large
View File


+ 90
- 0
tools/xsltsl/example.xsl View File

@@ -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: example.xsl,v 1.5 2002/01/04 23:43:17 balls Exp $
</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
- 0
tools/xsltsl/markup.xsl View File

@@ -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: markup.xsl,v 1.5 2003/03/31 21:07:28 balls Exp $
</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
- 0
tools/xsltsl/math.xsl View File

@@ -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: math.xsl,v 1.4 2004/10/08 06:37:25 balls Exp $
</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>
<xsl:text>eighteenth</xsl:text>
</xsl:when>
<xsl:when test='$number = 19'>
<xsl:if test='$preceding = 1'> and </xsl:if>
<xsl:text>nineteenth</xsl:text>
</xsl:when>
<xsl:when test='$number = 20'>
<xsl:if test='$preceding = 1'> and </xsl:if>
<xsl:text>twentieth</xsl:text>
</xsl:when>
<xsl:when test='$number = 30'>
<xsl:if test='$preceding = 1'> and </xsl:if>
<xsl:text>thirtieth</xsl:text>
</xsl:when>
<xsl:when test='$number = 40'>
<xsl:if test='$preceding = 1'> and </xsl:if>
<xsl:text>fortieth</xsl:text>
</xsl:when>
<xsl:when test='$number = 50'>
<xsl:if test='$preceding = 1'> and </xsl:if>
<xsl:text>fiftieth</xsl:text>
</xsl:when>
<xsl:when test='$number = 60'>
<xsl:if test='$preceding = 1'> and </xsl:if>
<xsl:text>sixtieth</xsl:text>
</xsl:when>
<xsl:when test='$number = 70'>
<xsl:if test='$preceding = 1'> and </xsl:if>
<xsl:text>seventieth</xsl:text>
</xsl:when>
<xsl:when test='$number = 80'>
<xsl:if test='$preceding = 1'> and </xsl:if>
<xsl:text>eightieth</xsl:text>
</xsl:when>
<xsl:when test='$number = 90'>
<xsl:if test='$preceding = 1'> and </xsl:if>
<xsl:text>ninetieth</xsl:text>
</xsl:when>

<xsl:when test='$number mod 1000000 = 0'>
<xsl:call-template name='math:number-as-word'>
<xsl:with-param name='number' select='floor($number div 1000000)'/>
</xsl:call-template>
<xsl:text> millionth</xsl:text>
</xsl:when>
<xsl:when test='$number &lt; 1000000 and $number mod 1000 = 0'>
<xsl:if test='$preceding = 1 and $conjunctive'> and </xsl:if>
<xsl:call-template name='math:number-as-word'>
<xsl:with-param name='number' select='floor($number div 1000)'/>
</xsl:call-template>
<xsl:text> thousandth</xsl:text>
</xsl:when>
<xsl:when test='$number &lt; 1000 and $number mod 100 = 0'>
<xsl:if test='$preceding = 1 and $conjunctive'> and </xsl:if>
<xsl:call-template name='math:number-as-word'>
<xsl:with-param name='number' select='floor($number div 100)'/>
</xsl:call-template>
<xsl:text> hundredth</xsl:text>
</xsl:when>

<xsl:when test='$number &gt; 1000000'>
<xsl:if test='$preceding = 1'>
<xsl:text> </xsl:text>
<xsl:if test='$conjunctive'>and </xsl:if>
</xsl:if>
<xsl:call-template name='math:number-as-word'>
<xsl:with-param name='number' select='floor($number div 1000000) * 1000000'/>
</xsl:call-template>
<xsl:choose>
<xsl:when
test='(floor(floor(($number mod 1000000) + 0.1) div 100000) > 0 and $number mod 100000 > 0) or
(floor(floor(($number mod 100000) + 0.1) div 10000) > 0 and $number mod 10000 > 0) or
(floor(floor(($number mod 10000) + 0.1) div 1000) > 0 and $number mod 1000 > 0) or
(floor(floor(($number mod 1000) + 0.1) div 100) > 0 and $number mod 100 > 0) or
(floor(floor(($number mod 100) + 0.1) div 10) > 0 and $number mod 10 > 0 and $number mod 100 > 20)'>
<xsl:text> </xsl:text>
<xsl:call-template name='math:ordinal-as-word'>
<xsl:with-param name='number' select='floor(($number mod 1000000) + 0.1)'/>
<xsl:with-param name='conjunctive' select='$conjunctive'/>
<xsl:with-param name='preceding' select='0'/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name='math:ordinal-as-word'>
<xsl:with-param name='number' select='floor(($number mod 1000000) + 0.1)'/>
<xsl:with-param name='conjunctive' select='$conjunctive'/>
<xsl:with-param name='preceding' select='1'/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test='$number &gt; 1000'>
<xsl:if test='$preceding = 1'>
<xsl:text> </xsl:text>
<xsl:if test='$conjunctive'>and </xsl:if>
</xsl:if>
<xsl:call-template name='math:number-as-word'>
<xsl:with-param name='number' select='floor($number div 1000) * 1000'/>
<xsl:with-param name='conjunctive' select='$conjunctive'/>
</xsl:call-template>
<xsl:choose>
<xsl:when test='floor(floor(($number mod 1000) + 0.1) div 100) > 0'>
<xsl:text> </xsl:text>
<xsl:call-template name='math:ordinal-as-word'>
<xsl:with-param name='number' select='floor(($number mod 1000) + 0.1)'/>
<xsl:with-param name='conjunctive' select='$conjunctive'/>
<xsl:with-param name='preceding' select='0'/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name='math:ordinal-as-word'>
<xsl:with-param name='number' select='floor(($number mod 1000) + 0.1)'/>
<xsl:with-param name='conjunctive' select='$conjunctive'/>
<xsl:with-param name='preceding' select='1'/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test='$number &gt; 100'>
<xsl:if test='$preceding = 1'>
<xsl:text> </xsl:text>
<xsl:if test='$conjunctive'>and </xsl:if>
</xsl:if>
<xsl:call-template name='math:number-as-word'>
<xsl:with-param name='number' select='floor($number div 100) * 100'/>
</xsl:call-template>
<xsl:call-template name='math:ordinal-as-word'>
<xsl:with-param name='number' select='floor(($number mod 100) + 0.1)'/>
<xsl:with-param name='conjunctive' select='$conjunctive'/>
<xsl:with-param name='preceding' select='1'/>
</xsl:call-template>
</xsl:when>

<xsl:when test='$number &gt; 20'>
<xsl:if test='$preceding = 1'>
<xsl:text> </xsl:text>
<xsl:if test='$conjunctive'>and </xsl:if>
</xsl:if>
<xsl:call-template name='math:number-as-word'>
<xsl:with-param name='number' select='floor($number div 10) * 10'/>
</xsl:call-template>
<xsl:text> </xsl:text>
<xsl:call-template name='math:ordinal-as-word'>
<xsl:with-param name='number' select='floor(($number mod 10) + 0.1)'/>
<xsl:with-param name='conjunctive' select='$conjunctive'/>
</xsl:call-template>
</xsl:when>

<xsl:otherwise/>
</xsl:choose>
</xsl:template>

<doc:template name="math:number-as-word" xmlns="">
<refpurpose>Returns a number as a word</refpurpose>

<refdescription>
<para>This template returns the word for a given integer number, for example "one" 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>Adds the word "and" where appropriate, for example.</para>
</listitem>
</varlistentry>
</variablelist>
</refparameter>

<refreturn>
<para>Returns the number as a string.</para>
</refreturn>
</doc:template>

<xsl:template name="math:number-as-word">
<xsl:param name="number" select="0"/>
<xsl:param name='conjunctive' select='true()'/>

<xsl:choose>

<xsl:when test='$number = 0'>zero</xsl:when>

<xsl:when test='$number &lt; 0'>
<xsl:text>minus </xsl:text>
<xsl:call-template name='math:number-as-word'>
<xsl:with-param name='number' select='-1 * $number'/>
</xsl:call-template>
</xsl:when>

<xsl:when test="$number != floor($number)"/>