Petr Nalevka wrote:
> 
> I have implemented a simple command to insert DocBook cross references
> using xref.
> 
> Here is the code:
>   <command name="db5.insertXref">
>     <macro repeatable="true" undoable="true" label="Insert XRef">
>       <sequence>
>         <pass>
>             <command name="insert" parameter="into
> {http://docbook.org/ns/docbook}xref
> <http://docbook.org/ns/docbook%7Dxref>"/>
>         </pass>
>         <command name="insert" parameter="into
> {http://docbook.org/ns/docbook}xref
> <http://docbook.org/ns/docbook%7Dxref>"/>
> 
>         <set variable="idList" expression="//@xml:id"/>
>         <get expression="$idList" />   
> 
>         <command name="pick" parameter="'Select crossreference linkend'
> false %_" />
>         <command name="putAttribute" parameter="linkend %_" />
>         <command name="insertString" parameter=" " />
>       </sequence>
>     </macro>
>   </command>
> 
> It works fine, but in a modular document environment it of course shows
> only ID from the current document fragment. If I rather use the
> attribute list dialog and click the "List of values" I get a much better
> list which includes also all xml:ids from included fragments. Would it
> be possible to implement such a comprehensive pick using the XXE commands?
> 
> Even better would be to get xml:ids not only from the current fragment
> and all included fragments but also from "Preceding" fragments recursively.
> 

Command putAttribute knows that linkend is an IDREF attribute. It will
automatically display the list of all IDs if you do not pass it an
attribute value.

See http://www.xmlmind.com/xmleditor/_distrib/doc/commands/putAttribute.html

Your macro can be rewritten as follows:
---
  <command name="db5.insertXref">
    <macro repeatable="true" undoable="true" label="Insert XRef">
      <sequence>
        <command name="insert" parameter="into
{http://docbook.org/ns/docbook}xref"/>
        <command name="putAttribute" parameter="linkend" />
        <command name="insertString" parameter=" " />
      </sequence>
    </macro>
  </command>
---

Note that the <pass> is definitely not needed. Your sequence will not be
executed if the schema does not allow an xref to be inserted at caret
position.





Reply via email to