Are variables (var) supported in XSLTforms or betterForm?

542 Views Asked by At

I've prepared the following XForms document based on http://www.w3.org/MarkUp/Forms/wiki/XForms_2.0#The_var_element:

<?xml-stylesheet type="text/xsl" href="../xsltforms/xsltforms.xsl"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms">
    <head>
        <title>var-demo</title>
        <xf:model>
            <xf:instance>
                <data xmlns="">
                    <PersonGivenName>Kilroy</PersonGivenName>
                </data>
            </xf:instance>
        </xf:model>
    </head>
    <body>
        <xf:output value="PersonGivenName"><xf:label>PersonGivenName=</xf:label></xf:output>

        <xf:var name="pg_name" value="PersonGivenName"/>
        <xf:output value="pg_name"><xf:label>pg_name=</xf:label></xf:output>
    </body>
</html>

It is very simple: should output (I think) Kilroy twice, first read directly from the model, then putting into a variable and printing that variable.

But the output is only

PersonGivenName=Kilroy
pg_name=

I've tried this from eXist-db 2.0 and eXide version 2.0. The code above is processed by XSLTforms; omitting the first line, it's processed by betterForm - but the result is the same.

The examples after chapter "3.2.4.2 Variable Scope" in http://www.w3.org/MarkUp/Forms/wiki/XForms_2.0 suggest that a $ prefix is needed when the value of the variable is used, but both XSLTforms and betterForm throw exception on changing the last output to value="$pg_name". The code above seems to be syntactically correct, but the value of the variable is not printed out. Can anybody explain this?

2

There are 2 best solutions below

0
On

Sorry, variables are not implemented yet in XSLTForms.

I frequently define a dedicated instance for "variables".

-Alain

1
On

Neither are they in betterFORM. You can use the pattern Alain describes or use a custom simple variable mechanism we've implemented before it occured in the spec:

We got a <xf:setvariable name="foo" value="bar"/> implementation. The resulting variable can then be used with the '$' notation in certain places or (more savely) by using bf:appContext('foo') XPath function.

  • Joern