How to use XPath 2.0 date functions in my xform

2 messages Options
Embed this post
Permalink
npujol73

How to use XPath 2.0 date functions in my xform

Reply Threaded More More options
Print post
Permalink
Ok guys, this may be an easy one I am trying to use this function
within my xform:

<xforms:output value="fn:subtract-dates($previousItemEndDate,$previousItemEndDate)"/>
but no luck, I get an error popup message indicating the function
cannot be found. I tried with/without the fn namespace.

Can anybody help? Thanks! Here is the xform:

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
    xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:widget="http://orbeon.org/oxf/xml/widget"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
xmlns:fn="http://www.w3.org/TR/xpath-functions" >
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <xforms:model id="fr-form-model">
            <xforms:instance id="data">
                <root xmlns="">
                    <item1>2009-01-01</item1>
                    <item2>2009-02-01</item2>
                </root>
            </xforms:instance>
            <xforms:bind nodeset="instance('data')/item1" required="true()"/>
            <xforms:bind nodeset="instance('data')/item2" required="true()"/>
        </xforms:model>
    </head>
    <body>
        <xforms:group ref="instance('data')">
            <xforms:input ref="item1">
                <xforms:label>Field1</xforms:label>
            </xforms:input>
            <xforms:input ref="item2">
                <xforms:label>Field2</xforms:label>
            </xforms:input>
            <xforms:trigger>
                <xforms:label>Add Entry</xforms:label>
                <xforms:action ev:event="DOMActivate">
                    <xxforms:variable name="currentItem" select="item1"/>
                    <xxforms:variable name="previousItem" select="item2"/>
                    <xforms:message><xforms:output
value="$currentItem"/>,<xforms:output
value="$previousItem"/></xforms:message>
                    <xxforms:variable name="previousItemEndDate"
value="xs:date($previousItem)"/>
                    <xxforms:variable name="currentItemStartDate"
value="xs:date($currentItem)"/>
                    <xforms:message><xforms:output
value="fn:subtract-dates($previousItemEndDate,$previousItemEndDate)"/></xforms:message>
                </xforms:action>
            </xforms:trigger>
        </xforms:group>
    </body>
</html>


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Hank Ratzesberger

Re: How to use XPath 2.0 date functions in my xform

Reply Threaded More More options
Print post
Permalink
Hi Nicolas,

A good reference is :

http://www.w3.org/TR/xpath-functions/

where I notice that subtract dates is an operator (op:) so that
the parser allows you to use it intrinsically:

myDate1 - myDate2

You may specifically need to cast for the parser to recognize:

xs:date(myDate1) - xs:date(myDate2)

Regards,
Hank

On Nov 9, 2009, at 10:11 AM, Nicolas Pujol wrote:

> Ok guys, this may be an easy one I am trying to use this function
> within my xform:
>
> <xforms:output value="fn:subtract-dates($previousItemEndDate,
> $previousItemEndDate)"/>
> but no luck, I get an error popup message indicating the function
> cannot be found. I tried with/without the fn namespace.
>
> Can anybody help? Thanks! Here is the xform:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <html xmlns="http://www.w3.org/1999/xhtml"
> xmlns:xforms="http://www.w3.org/2002/xforms"
> xmlns:xhtml="http://www.w3.org/1999/xhtml"
>     xmlns:ev="http://www.w3.org/2001/xml-events"
> xmlns:widget="http://orbeon.org/oxf/xml/widget"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
>     xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
> xmlns:fn="http://www.w3.org/TR/xpath-functions" >
>     <head>
>         <meta http-equiv="Content-Type" content="text/html;  
> charset=UTF-8"/>
>         <xforms:model id="fr-form-model">
>             <xforms:instance id="data">
>                 <root xmlns="">
>                     <item1>2009-01-01</item1>
>                     <item2>2009-02-01</item2>
>                 </root>
>             </xforms:instance>
>             <xforms:bind nodeset="instance('data')/item1"  
> required="true()"/>
>             <xforms:bind nodeset="instance('data')/item2"  
> required="true()"/>
>         </xforms:model>
>     </head>
>     <body>
>         <xforms:group ref="instance('data')">
>             <xforms:input ref="item1">
>                 <xforms:label>Field1</xforms:label>
>             </xforms:input>
>             <xforms:input ref="item2">
>                 <xforms:label>Field2</xforms:label>
>             </xforms:input>
>             <xforms:trigger>
>                 <xforms:label>Add Entry</xforms:label>
>                 <xforms:action ev:event="DOMActivate">
>                     <xxforms:variable name="currentItem"  
> select="item1"/>
>                     <xxforms:variable name="previousItem"  
> select="item2"/>
>                     <xforms:message><xforms:output
> value="$currentItem"/>,<xforms:output
> value="$previousItem"/></xforms:message>
>                     <xxforms:variable name="previousItemEndDate"
> value="xs:date($previousItem)"/>
>                     <xxforms:variable name="currentItemStartDate"
> value="xs:date($currentItem)"/>
>                     <xforms:message><xforms:output
> value="fn:subtract-dates($previousItemEndDate,
> $previousItemEndDate)"/></xforms:message>
>                 </xforms:action>
>             </xforms:trigger>
>         </xforms:group>
>     </body>
> </html>
>
> --
> You receive this message as a subscriber of the [hidden email]  
> mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws
Hank Ratzesberger
NEES@UCSB
Institute for Crustal Studies,
University of California, Santa Barbara
805-893-8042







--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws