zepheira / amara

Amara 2.0. Amara XML toolkit is an open-source collection of Python tools for XML processing, not just tools that happen to be written in Python, but tools built from the ground up to use Python idioms and take advantage of the many advantages of Python over other programming languages.
http://wiki.xml3k.org/Amara2
Apache License 2.0
23 stars 9 forks source link

EXSLT dates-and-times seems to be broken #20

Open mied opened 9 years ago

mied commented 9 years ago

I want to use the date xslt extension for some xml/xslt transformations but the implementation seems to be broken. I use this test file to check if the date functions work:

from amara.xslt import transform

XML_DOC = """<?xml version="1.0"?>
<durations>
    <duration>P4Y8MT7H</duration>
    <duration>P17Y1MT2H</duration>
    <duration>P1Y2MT2H</duration>
</durations>"""
XSL_STYLESHEET = """<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:date="http://exslt.org/dates-and-times">
<xsl:output method="html" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<out>
    <datetime><xsl:value-of select="date:date-time()"/></datetime>
    <date><xsl:value-of select="date:date('2000-01-02T03:04:05Z')"/></date>
    <time><xsl:value-of select="date:time('2000-01-02T03:04:05Z')"/></time>
    <year><xsl:value-of select="date:year('2000-01-02T03:04:05Z')"/></year>
    <leapyear><xsl:value-of select="date:leap-year('2000-01-02T03:04:05Z')"/></leapyear>
    <monthinyear><xsl:value-of select="date:month-in-year('2000-01-02T03:04:05Z')"/></monthinyear>
    <monthname><xsl:value-of select="date:month-name('2000-01-02T03:04:05Z')"/></monthname>
    <monthabbreviation><xsl:value-of select="date:month-abbreviation('2000-01-02T03:04:05Z')"/></monthabbreviation>
    <weekinyear><xsl:value-of select="date:week-in-year('2000-01-02T03:04:05Z')"/></weekinyear>
    <dayinyear><xsl:value-of select="date:day-in-year('2000-01-02T03:04:05Z')"/></dayinyear>
    <dayinmonth><xsl:value-of select="date:day-in-month('2000-01-02T03:04:05Z')"/></dayinmonth>
    <dayofweekinmonth><xsl:value-of select="date:day-of-week-in-month('2000-01-02T03:04:05Z')"/></dayofweekinmonth>
    <dayinweek><xsl:value-of select="date:day-in-week('2000-01-02T03:04:05Z')"/></dayinweek>
    <dayname><xsl:value-of select="date:day-name('2000-01-02T03:04:05Z')"/></dayname>
    <dayabbreviation><xsl:value-of select="date:day-abbreviation('2000-01-02T03:04:05Z')"/></dayabbreviation>
    <hourinday><xsl:value-of select="date:hour-in-day('2000-01-02T03:04:05Z')"/></hourinday>
    <minuteinhour><xsl:value-of select="date:minute-in-hour('2000-01-02T03:04:05Z')"/></minuteinhour>
    <secondinminute><xsl:value-of select="date:second-in-minute('2000-01-02T03:04:05Z')"/></secondinminute>
    <formatdate><xsl:value-of select="date:format-date('2000-01-02T03:04:05Z', 'EEE, d MMM yyyy HH:mm:ss')"/></formatdate>
    <weekinmonth><xsl:value-of select="date:week-in-month('2000-01-02T03:04:05Z')"/></weekinmonth>
    <difference><xsl:value-of select="date:difference('2000-01-01T00:00:00Z', '2000-01-02T03:04:05Z')"/></difference>
    <add><xsl:value-of select="date:add('2000-01-02T03:04:05Z', 'P1DT1H1M1S')"/></add>
    <addduration><xsl:value-of select="date:add-duration('P4DT4H4M4S', 'P1DT2H3M4S')"/></addduration>
    <sum><xsl:value-of select="date:sum(//duration)"/></sum>
    <seconds><xsl:value-of select="date:seconds('2000-01-02T03:04:05Z')"/></seconds>
    <duration><xsl:value-of select="date:duration('93784')"/></duration>
</out>
</xsl:template>
</xsl:stylesheet>"""

print transform(XML_DOC, XSL_STYLESHEET)

Runing this file fails with a stack trace. It seems like the implementation in amara/xslt/exslt/datetime.py is broken (missing imports,...). Did I do something wrong or can somebody else confirm this?