Skip to content

Instantly share code, notes, and snippets.

@wsalesky
Created February 1, 2022 01:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wsalesky/bfae273a9b6988dbe68bb0025eb4886e to your computer and use it in GitHub Desktop.
Save wsalesky/bfae273a9b6988dbe68bb0025eb4886e to your computer and use it in GitHub Desktop.
XForms repeats following XML document order.
<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" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<head>
<title>Insert with Origin</title>
<style type="text/css">
@namespace xf url("http://www.w3.org/2002/xforms");
body {font-family:Helvetica, sans-serif}
</style>
<xf:model>
<xf:instance id="i-rec">
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<handDesc hands="">
<summary/>
<handNote xml:id="" scope="" script="" mode="" quality="" medium="">
<p about="" style=""/>
<persName ref="" role=""/>
<p/>
<placeName ref=""/>
</handNote>
</handDesc>
</TEI>
</xf:instance>
<xf:instance id="i-elementTemplate">
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<p/>
<persName ref="" role=""/>
<placeName ref=""/>
<metamark function=""/>
<locus from="" to=""/>
<origDate when="" notAfter="" notBefore=""/>
</TEI>
</xf:instance>
<xf:instance id="i-position">
<data>
<position></position>
</data>
</xf:instance>
</xf:model>
</head>
<body style="margin:2em 10em;">
<div class="container">
<h2>Output in document order</h2>
<p>Outputs inputs in document/instance order. Adding a new p element always results in a p element added as the first child of tei:handNote, not as last, or after the current element.</p>
<xf:repeat ref="instance('i-rec')//*:handNote/*" id="handNote">
<xf:input ref=".">
<xf:label>
<xf:output value="local-name(.)"/>
</xf:label>
</xf:input>
<xf:repeat ref="@*" id="atts">
<xf:input ref=".">
<xf:label>
<xf:output value="local-name(.)"/>
</xf:label>
</xf:input>
</xf:repeat>
<xf:trigger class="btn add" appearance="minimal">
<xf:label>new p</xf:label>
<xf:insert ev:event="DOMActivate"
ref="." at="." position="after"
origin="instance('i-elementTemplate')//*:p"/>
</xf:trigger>
</xf:repeat>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment