On 04/30/2015 09:37 PM, Boris Goldowsky wrote:
I’m trying to make a configuration that allows for convenient building
of “Cloze passages”, which are essentially fill-in-the-blanks exercises
like this:

The quick ______ jumped over the ______ …

Or in XML:     <clozepassage><p>The quick <clozeword/> jumped over the
<clozeword>…. </p></clozepassage>

I want to have a command button after the <clozepassage> that adds a
<clozeword/> at the end (but inside the <p>), unless the last node is
already a <clozeword/>.

I am just running into a little trouble since I need to select the
/last/ /node that’s a descendant/ of <clozepassage>.  Not last child,
which would be the <p>, but the text node that’s “…” in this example.
There might be more structure in the way – it could be multiple
paragraphs, or a list with list items instead of a paragraph, for
instance.   I don’t see how to do this with selectNode, or what
alternative methods there might be?


A powerful, XPath 1.0 based, alternative to command "selectNode" is the <set> descendant element of <macro>:

---
<set
  variable = QName
  context = XPath expr. returning a node set : "/"
  expression = XPath expression
  plainString = boolean : false
/>
---

Some variable names are ``mapped'' to the node selection: "selected", "selected2", "selectedElement", "selectedNode", "selectedNodes".

Example: starting from implicitly selected element, select the closest ancestor having a "linkend" attribute:

---
<set variable="selectedElement" context="$implicitElement"
     expression="(ancestor-or-self::*[@linkend])[last()]" />
---



References:

* Macro commands, Reference,
http://www.xmlmind.com/xmleditor/_distrib/doc/commands/macro_reference.html

* XPath variables
http://www.xmlmind.com/xmleditor/_distrib/doc/commands/xpath_vars.html

* Command selectNode
http://www.xmlmind.com/xmleditor/_distrib/doc/commands/selectNode.html


--
XMLmind XML Editor Support List
[email protected]
http://www.xmlmind.com/mailman/listinfo/xmleditor-support

Reply via email to