Skip to content
Hub Nexus

No author yetClaim it

Version 1Updated 2 min read

Support

Motivation

You want to display a repeated set of URLs in a section of your form. Each URL is created by concatenating a base URL and a URL parameter.

Method

The equivalent of the HTML anchor tag () in an XForms application is the element.

If in a web page, you want your output to appear like this:

class="links">
href="http://www.example.com/myservice.xq?id=1">One
href="http://www.example.com/myservice.xq?id=2">Two
href="http://www.example.com/myservice.xq?id=3">Three

in an XForms application each anchor will be xf:load.

Your input instance is like the following:

id="link-items" xmlns="">

1
One

2
Two

3
Three

Discussion

With XForms it is not possible to create dynamic links inside a repeat using a combination of output, value and concat. This would also impact the ability to notify the user that is navigating away from a form.

There are two ways to display a list of links. Both use a trigger with the button appearance turned off. The first uses a load after setting a temporary instance. The second uses a submit/submission combination.

Using load

You can also use the load element as the element.

id="URL-container" xmlns="">

appearance="minimal">
One
ev:event="DOMActivate">
ref="instance('URL-container')"
value="concat('http://www.example.com/my-view.xq?id=', id)"/>
ref="instance('URL-container')"/>

Load XForms Application

Sample Program

The following program displays a list of links in a horizontal row. Each link has a label and a URL suffix that is extracted from an instance document.

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xf="http://www.w3.org/2002/xforms">
<head>
<title>Displaying Links in an XForms Application</title>
<style type="text/css">
@namespace xf url("http://www.w3.org/2002/xforms");
body {font-family:Helvetica, sans-serif}
.links xf|repeat * {display: inline;}
.url {color: blue; text-decoration:underline; margin: 0 2px;}
</style>
<xf:model>
<xf:instance xmlns="" id="links">
<data>
<link>
<label>XForms</label>
<wikipedia-id>XForms</wikipedia-id>
</link>
<link>
<label>XQuery</label>
<wikipedia-id>XQuery</wikipedia-id>
</link>
<link>
<label>XSLT</label>
<wikipedia-id>XSL Transformations</wikipedia-id>
</link>
<link>
<label>XML Database</label>
<wikipedia-id>XML_database</wikipedia-id>
</link>
<link>
<label>Declarative Programming</label>
<wikipedia-id>Declarative_programming</wikipedia-id>
</link>
<link>
<label>Functional Programming</label>
<wikipedia-id>Functional_programming</wikipedia-id>
</link>
</data>
</xf:instance>
<xf:instance id="URL-container" xmlns="">
<URL />
</xf:instance>
</xf:model>
</head>
<body>
<h3>Displaying Links in an XForms Application</h3>
<div class="links">
<xf:repeat nodeset="instance('links')/link" id="link-repeat">
<xf:trigger submission="replace-form-with" appearance="minimal" class="url">
<xf:label>
<xf:output ref="label" />
</xf:label>
<xf:hint>
<xf:output ref="wikipedia-id" />
</xf:hint>
<xf:action ev:event="DOMActivate">
<xf:setvalue ref="instance('URL-container')" value="concat('http://en.wikipedia.org/wiki/', instance('links')/link[index('link-repeat')]/wikipedia-id)" />
<xf:load ref="instance('URL-container')" />
</xf:action>
</xf:trigger>
</xf:repeat>
</div>
</body>
</html>

Acknowledgment

This solution was posted to the Mozilla XForms development newsgroup by John Clark on February 27th, 2008.

As an alternative strategy you can replace a form by using the submission statement with a replace="all" attribute. You can then style the submission button using appearance="minimal" and make the button look like a link:

type="text/css">
@namespace xf url("http://www.w3.org/2002/xforms");
.url {color: blue; text-decoration:underline; margin: 0 2px;}

...
id="replace-form-with" method="get"
ref="instance('link-items')/item[index('link-repeat')]/id"
action="http://www.example.com/my-view.xq"
replace="all" />
...
nodeset="instance('link-items')/item" id="link-repeat">
submission="replace-form-with" appearance="minimal" class="url">
ref="label"/>

The only disadvantage of this solution over using standard links is that the URL does not display in the status bar. This problem can be mitigated by using the xf:hint element within the label. This text will display when the user hovers over the link.

This method also allows you to interrupt the submission, check for changes in instance data and display warning messages before a form is unloaded.

Where this page came from

This page was imported from Wikibooks. From “XForms” on Wikibooks, by its contributors, under CC BY-SA 4.0. Changed here: set as a page; navigation and edit links left out; each image under its own licence, credited in its caption.

Nobody has written it yet — it is the source material at a new address, which is why search engines are asked to skip it and why no one earns from it. It is up for grabs: take it on, and it is yours to rewrite and to earn from.

Get each new page of

XForms

Following means one email when a page is added, nothing when a page changes.

Following means one email when a page is added, nothing when a page changes.

Comments

Spinner Logo

Next in XForms

CC BY-SA 4.0
XForms, Switch and Case
CC BY-SA 4.0
ref="/var/first" > Should I show the second question? /> select="yes"> Yes Please! 1 No Thank You 0 /> ref="/var/second"> Second value: ## Using Multiple Predicates in Binds Sometimes you have a sequence of many items and the display of one item depends on the values of other items. Predicates are a
CC BY-SA 4.0
Then we add a predicate to turn on or off that entire group. In this case if the code is "yes" the input field will be displayed. If it is not the field will be hidden. ref=".[code='yes']"> ref="field"> Conditional Display: ## Complete Example xmlns=" xmlns:xf=" Binds in Repeats type="text/css"> @na
CC BY-SA 4.0
When you are done setting the months the control is set back to the hidden mode. ![XForms Control Visible]( XForms Control Visible (Image: The original uploader was Dmccreary at English Wikibooks ., CC BY-SA 3.0) ## Sample Code xmlns=" xmlns:xf=" xmlns:ev=" Show/Hide Control type="text/css"> @namesp
CC BY-SA 4.0
John Fred Sue Here is an example of this rule: id="triggerDisplay" nodeset="display-delete" relevant="count(/data/person) > 1"/> The above uses the XPath count() function with the greater than operator. But since it must be escaped you must use the ">" instead of ">". Or alternatively the delete but
CC BY-SA 4.0
For example, suppose you had a set of fields related to shipping supplies to remote staff in your IT department. The billing address could not be changed, only who an item was shipped to. The following single line in the model would make all of the sub-elements of BillToAddress read-only: nodeset="/