Skip to content

Instantly share code, notes, and snippets.

@timathom
Last active August 29, 2015 14:23
Show Gist options
  • Save timathom/5c1da9c314eadc892282 to your computer and use it in GitHub Desktop.
Save timathom/5c1da9c314eadc892282 to your computer and use it in GitHub Desktop.
XForms select-all-by-group checkboxes in XSLTForms
<?xml-stylesheet type="text/xsl" href="http://localhost:8080/exist/apps/xsltforms/xsltforms.xsl"?><?css-conversion no?><?xsltforms-options debug="yes"?><?xml-model href="http://www.oxygenxml.com/1999/xhtml/xhtml-xforms.nvdl" schematypens="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0"?>
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:bf="http://bibframe.org/vocab/"
xmlns:cwb="http://libserv6.princeton.edu/cwb/"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<head>
<meta
content="text/html; charset=UTF-8"
http-equiv="Content-Type" />
<meta
content="IE=edge"
http-equiv="X-UA-Compatible" />
<title>Select-all-by-group demo</title>
<xf:model
id="table">
<xf:instance
id="results">
<cwb:data>
<cwb:result>
<cwb:resources>
<Agent>
<bf:Agent
cwb:selected="false"
label="Agent"
ns="http://bibframe.org/vocab/"
subClassOf="http://bibframe.org/vocab/Authority"
type="Class"></bf:Agent>
<bf:Family
cwb:subselected="false"
label="Family"
ns="http://bibframe.org/vocab/"
subClassOf="http://bibframe.org/vocab/Agent"
type="Class"></bf:Family>
<bf:Organization
cwb:subselected="false"
label="Organization"
ns="http://bibframe.org/vocab/"
subClassOf="http://bibframe.org/vocab/Agent"
type="Class"></bf:Organization>
<bf:Person
cwb:subselected="false"
label="Person"
ns="http://bibframe.org/vocab/"
subClassOf="http://bibframe.org/vocab/Agent"
type="Class"></bf:Person>
</Agent>
<Resource>
<bf:Resource
cwb:selected="false"
label="Resource"
ns="http://bibframe.org/vocab/"
type="Class"></bf:Resource>
<bf:Annotation
cwb:subselected="false"
label="Annotation"
ns="http://bibframe.org/vocab/"
subClassOf="http://bibframe.org/vocab/Resource"
type="Class"></bf:Annotation>
<bf:Category
cwb:subselected="false"
label="Category"
ns="http://bibframe.org/vocab/"
subClassOf="http://bibframe.org/vocab/Resource"
type="Class"></bf:Category>
<bf:Classification
cwb:subselected="false"
label="Classification Entity"
ns="http://bibframe.org/vocab/"
subClassOf="http://bibframe.org/vocab/Resource"
type="Class"></bf:Classification>
</Resource>
</cwb:resources>
</cwb:result>
</cwb:data>
</xf:instance>
<!--
Set datatypes of instance variables.
@cwb:selected is the group selector,
@cwb:subselected is the selector for each item.
-->
<xf:bind
nodeset="instance('results')/cwb:result/cwb:resources/*/*/@cwb:selected"
type="xs:boolean"></xf:bind>
<xf:bind
nodeset="instance('results')/cwb:result/cwb:resources/*/*/@cwb:subselected"
type="xs:boolean"></xf:bind>
</xf:model>
</head>
<body style="margin:2%;">
<h1>Select-all-by-group demo</h1>
<table
class="table table-striped">
<thead>
<tr>
<th>Class</th>
<th>Subclass</th>
<th>Label</th>
</tr>
</thead>
<tbody>
<xf:repeat
id="repeat-vocab"
nodeset="instance('results')/cwb:result/cwb:resources/*/*">
<tr>
<td>
<!-- Set the checkbox for the group. -->
<xf:group
ref=".[count(preceding-sibling::*) = 0]">
<xf:input
incremental="true"
ref="@cwb:selected">
<xf:label></xf:label>
<!--
Each time it's checked, update the values of the following
items in the group, using the XForms 2.0 @iterate attribute.
-->
<xf:action
ev:event="xforms-value-changed">
<xf:setvalue
iterate="../../*/@cwb:subselected"
ref="context()"
value="
choose(
../../*/@cwb:selected = 'true',
'true',
'false'
)"></xf:setvalue>
</xf:action>
</xf:input>
</xf:group>
<xf:output
value="local-name(.[count(preceding-sibling::*) = 0])"></xf:output>
</td>
<td>
<!--
Set a separate checkbox for individual items,
to allow them to be changed independently.
-->
<xf:input
incremental="true"
ref="@cwb:subselected">
<xf:label></xf:label>
</xf:input>
<xf:group
ref=".[@ns = 'http://bibframe.org/vocab/']">
<a
href="http://bibframe.org/vocab/{local-name()}.html">
<xf:output
value="name(.[count(preceding-sibling::*) &gt;= 1])"></xf:output>
</a>
</xf:group>
<xf:group
ref=".[@ns != 'http://bibframe.org/vocab/']">
<xf:output
value="name()"></xf:output>
</xf:group>
</td>
<td>
<xf:output
ref=".[count(preceding-sibling::*) &gt;= 1]/@label"></xf:output>
</td>
</tr>
</xf:repeat>
</tbody>
</table>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment