$(xslt_eval(...)} editor variable
Posted: Thu Oct 14, 2021 1:22 pm
Hi,
I find myself regularly writing author mode actions with complex XPath expressions. These expressions generate values and labels for comboboxes or radio buttom in user dialogs from project content. E.g. like in this author mode action which inserts an element and an attribute to encode a bibliographic reference.
(The path ${framework}/samples/biblio.xml is actually rewritten using an xml catalog.)
However, these XPath-Expressions are really a mess when it comes to debugging and mainting code. It would be much more maintainable when one would be able to source out the code that generates the string for values and labels into an external script. IMO XSLT or XQuery would be best suited for this and it could be tested with Xspec.
So instead of it would be great to write or more precisely
Could you imagine adding a feature like this? Are there alternatives?
Regards,
Chris
I find myself regularly writing author mode actions with complex XPath expressions. These expressions generate values and labels for comboboxes or radio buttom in user dialogs from project content. E.g. like in this author mode action which inserts an element and an attribute to encode a bibliographic reference.
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<a:authorAction xmlns:a="http://www.oxygenxml.com/ns/author/external-action"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.oxygenxml.com/ns/author/external-action http://www.oxygenxml.com/ns/author/external-action/authorAction.xsd"
id="edit_bibref">
<a:name>Edit bibliographic reference</a:name>
<a:description>Inserts or changes a bibliographic reference.</a:description>
<a:operations>
<a:operation id="InsertFragmentOperation">
<a:xpathCondition>self::note</a:xpathCondition>
<a:arguments>
<a:argument name="fragment"><![CDATA[<bibl xmlns="http://www.tei-c.org/ns/1.0" corresp="${ask('Choose entry from bibliography', combobox, (${xpath_eval(let $biblio := doc('${framework}/samples/biblio.xml') return string-join(for $entry in $biblio//*:body//*:listBibl//*:bibl return concat("'", '#', $entry/@xml:id, "':'", replace(normalize-space($entry), "'", ' '), "'"), ';'))}), '')}"/>]]></a:argument>
</a:arguments>
</a:operation>
<a:operation id="ChangeAttributeOperation">
<a:xpathCondition>self::bibl[not(parent::listBibl)]</a:xpathCondition>
<a:arguments>
<a:argument name="elementLocation">self::bibl</a:argument>
<a:argument name="name">corresp</a:argument>
<a:argument name="value"><![CDATA[${ask('Choose entry from bibliography', combobox, (${xpath_eval(let $biblio := doc('${framework}/samples/biblio.xml') return string-join(for $entry in $biblio//*:body//*:listBibl//*:bibl return concat("'", '#', $entry/@xml:id, "':'", replace(normalize-space($entry), "'", ' '), "'"), ';'))}), '${xpath_eval(@corresp)}')}]]></a:argument>
</a:arguments>
</a:operation>
</a:operations>
<a:accessKey/>
</a:authorAction>
However, these XPath-Expressions are really a mess when it comes to debugging and mainting code. It would be much more maintainable when one would be able to source out the code that generates the string for values and labels into an external script. IMO XSLT or XQuery would be best suited for this and it could be tested with Xspec.
So instead of
Code: Select all
${xpath_eval(...)}
Code: Select all
${xslt_eval(...)}
Code: Select all
${xslt_eval('stylesheet.xsl', 'start-template', (param1: value1, param2: value2, ...))}
Regards,
Chris