Discussion:
XForms form internationalisation, an optimal means?
Stephen Cameron
2014-06-07 13:30:37 UTC
Permalink
Hi

I have an XForm that is internationalised (ized), and it seems now via use
of the profiler that alot of the slowness in my form might be attributable
to that fact. So I am interested to find a better way if possible to
achieve the same goal as what I currently have.

I see that @ref is now supported on <xf:label> elements, so that is
something to try:
http://www.agencexml.com/xforms-tests/testsuite/XForms1.1/Edition1/Chapt08/8.2/8.2.1/8.2.1.a.xhtml

What I have a present is a second model for my label strings and this has a
single instance with data of the following structure:

<?xml version="1.0" encoding="UTF-8"?>
<labels lang="en">
<languages>
<language lang="en">English</language>
<language lang="es">Español</language>
<language lang="fr">Français</language>
</languages>
<label-set id="header-title">
<label lang="en">Forms-Wizard Designer (alpha)</label>
<label lang="es">Forms-Wizard Designer (alpha)</label>
<label lang="fr">Forms-Wizard Designer (alpha)</label>
</label-set>

The label-set strings are used in the following way in the form:

<xf:input ref="@name">
<xf:label>
<xf:output model="model2"
ref="label-set[@id='name']/label[@lang=../../@lang]" />
</xf:label>

Apparently these label <xf:output> references get re-evaluated each time
there is a recalculation of the form. I did imagine (naively) that this
would not happen if they where placed into a second model, but that doesn't
seem to be what is happening in practice.

Also, I should be able to make that @xml:id to get a quicker scan of the
labels model I suppose, but does XSLTForms support @id attributes as unique
identifiers in data models?

Thanks for your insights.

Steve Cameron
a***@public.gmane.org
2014-06-09 03:47:32 UTC
Permalink
Hi Steve,
Post by Stephen Cameron
I have an XForm that is internationalised (ized), and it seems now via use
of the profiler that alot of the slowness in my form might be attributable to
that fact. So I am interested to find a better way if possible to achieve the
same goal as what I currently have.
http://www.agencexml.com/xforms-tests/testsuite/XForms1.1/Edition1/Chapt08/8.2/8.2.1/8.2.1.a.xhtml
What I have a present is a second model for my label strings and this has
<?xml version="1.0" encoding="UTF-8"?>
<labels lang="en">
<languages>
<language lang="en">English</language>
<language lang="es">Español</language>
<language lang="fr">Français</language>
</languages>
<label-set id="header-title">
<label lang="en">Forms-Wizard Designer (alpha)</label>
<label lang="es">Forms-Wizard Designer (alpha)</label>
<label lang="fr">Forms-Wizard Designer (alpha)</label>
</label-set>
<xf:label>
<xf:output model="model2"
</xf:label>
I presume that there is another control such as a select1 to change
/labels/@lang value, is that right?

The caveat with that is that the corresponding instance cannot be stamped as a
read-only one and XSLTForms will check its contents for validation each time it
will consider it necessary.

XPath evaluation for expressions such as "elt[@attr = 'value']" requires, first,
to retrieve all elements named "elt" then to apply a filter to each one. It
sounds like a relational approach with a key. This is not the most optimized XML
structure for XPath.

It would be more efficient to define a sort of map with attributes (elements
would be nicer for rich text values but a bit slower). In your example,
something like this:

<labels lang="en">
<label-set lang="en" header-title="Forms-Wizard Designer
(alpha)">English</label-set>
<label-set lang="es" header-title="Forms-Wizard Designer
(alpha)">Español</label-set>
<label-set lang="fr" header-title="Forms-Wizard Designer
(alpha)">Français</label-set>

and

ref="label-set[@lang=../@lang]/@header-title"

You could, even, add an action to copy the corresponding label-set into a work
instance each time the select1 control has its value changed (not very often, I
presume). It will, then, remove the lang predicate! With XForms 2.0, using a
variable will be even better.

BTW, there is also the itext ODK extension
(http://www.agencexml.com/xsltforms/address.xml) but it does not specify how to
change from one language to another so it is just getting the browser current
language.

I am convinced that XPath 3.1 maps will be useful for performance and JSON/XML
convergence. I am already experimenting them in my own DOM implementation in
Javascript to be used as a replacement for DOM4!
Post by Stephen Cameron
Apparently these label <xf:output> references get re-evaluated each time
there is a recalculation of the form. I did imagine (naively) that this would
not happen if they where placed into a second model, but that doesn't seem to
be what is happening in practice.
Dependencies should say that this is not required but I would have to check this
more deeply...
Post by Stephen Cameron
identifiers in data models?
Yes, id() function calls mixed with @xml:id usage should improve this.

Thank you for your feedback!

--Alain

Loading...