Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mied opened this issue Feb 4, 2015 · 0 comments
Open

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

mied opened this issue Feb 4, 2015 · 0 comments

Comments

@mied
Copy link

mied commented Feb 4, 2015

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant