Huditsch, Roman (LNG-VIE) wrote:
> 
> I'm struggling to insert a PI node with the insertNode command.
> Here is the code I have at the moment:
> 
> <cfg:command name="selectNode"
> parameter="ancestorOrSelf[implicitElement] artikel"/>
> <cfg:command name="MultiPrompt" parameter="Stichwort Hauptstichwort
> Substichwort"/>
> <cfg:set variable="keywords" expression="%_" plainString="true"/>
> <cfg:get expression="concat('stichworteintrag ', $keywords)"/>
> <cfg:command name="insertNode" parameter="piInto %_"/>
> 
> 
> The MultiPrompt command returns the string "Stichwort1 | Stichwort2"
> 
> I would like to generate a PI like <?stichworteintrag Stichwort1 |
> Stichwort2?>
> 
> Do you have any hint how to achieve this output?

What follows is a similar macro, which can be tested using a DocBook 4 
article:

---
<binding>
   <keyPressed code="F3" />
   <command name="insertPI" />
</binding>

<command name="insertPI">
   <macro undoable="true">
     <sequence>
       <command name="selectNode"
                parameter="ancestorOrSelf[implicitElement] article"/>

       <!-- The target of the inserted PI is always 'testIt'.
            Its text contents is specified by the user. -->

       <command name="prompt"
                parameter="Question 'Contents of the testIt PI:"/>
       <set variable="piContents" expression="%_" plainString="true"/>

       <!-- Insert PI inside empty article (not possible in DocBook,
            but may be with your custom DTD) when possible or
            before firstChild otherwise. -->

       <choice>
         <command name="insertNode" parameter="piInto testIt"/>

         <sequence>
           <command name="selectNode" parameter="firstChild"/>
           <command name="insertNode" parameter="piBefore testIt"/>
         </sequence>
       </choice>

       <!-- The testIt PI being selected after last command,
            now insert the text contents at caret position. -->

       <get variable="piContents" expression="$piContents"/>
       <command name="paste" parameter="into %_" />
     </sequence>
   </macro>
</command>
---

Reply via email to