Vivian River
Vivian River

Reputation: 32390

How to declare a duration variable in XSLT 2.0?

I'm using the Saxon library to apply some XSLT 2.0 transformations.

I'm trying to add some code that will print all the dates between two given dates.

To that end, I'm trying to figure out to work with duration variables. Specifically, I want to take the first date, add one day to it, print it, and then repeat until the first date has been increased all the way up to the second date.

I've written the following in my XSLT:

  <xsl:template name="get_rundatesNode">
    <xsl:param name="startDate" />
    <xsl:param name="endDate" />
    <xsl:variable name="oneDay" select='xs:dayTimeDuration("P1D")' />

  </xsl:template>

I see the following errors from Saxon:

Error at /xsl:stylesheet/xsl:template[2]/xsl:variable[1] XPST0081 XPath syntax error at char 0 on line -1 in {xs:dayTimeDuration("P1D"} : Undeclared namespace prefix {xs} Warning: at /xsl:stylesheet/xsl:template[2]/xsl:variable[1] SXWN9001: A variable with no following sibling instructions has no effect

I think I'm probably using the wrong syntax and I'm totally confused by the documentation. I can't find an example of this being done correctly. Please let me know how to make it work.

Upvotes: 0

Views: 1959

Answers (1)

G. Ken Holman
G. Ken Holman

Reputation: 4403

All you need is a declaration at the top of your stylesheet that binds the xs prefix to the W3C schema namespace, probably also with a directive to prune the copying of namespaces to the result tree:

            xmlns:xs="http://www.w3.org/2001/XMLSchema"
            exclude-result-prefixes="xs"

The warning is just telling you that you haven't finished adding code yet to your template and so the variable isn't going to do anything for you.

Upvotes: 2

Related Questions