Mariusz Idzikowski wrote:
>  
> I'm stuck with the following problem. Let's say there is a document
> containing elements following this pattern:
>  
> <book id="a1234" title="Pride and Prejudice"/>
>  
> I'd like to create a macro that would provide the user with a list of
> all titles present in a document and return the id corresponding to
> the title they select.
>  
> It is easy to create a list of all id's in the document and use that
> list as arguments to the pick command:
>  
> <get expression="join(//book/@id, ' ' )"/>
> <command name="pick" parameter="'Select a title'  false  %_"/>
>  
> but a list of id's is of course meaningless to any user. Is it possible
> then to *dynamically* create a list that would contain both items (id)
> and labels (title) and be suitable for the pick command, given the
> built-in implementation of XPath and the available macro commands?
>  
> Any hint will be appreciated.

To my knowledge, there is no way to do this in one step using our (fully
conformant) XPath 1.0 implementation alone.

It would have been possible to do this in one step with XPath 2.0 or
with XPath 1.0+a simple XPath extension function written in Java.

The workaround is to use *two* steps:

[1] Let the user pick the title of a book.

<get expression="concat('&quot;',
                        join(//book/@title, '&quot; &quot;'),
                        '&quot;')"/>
<!-- %_ is thus something like:
"Pride and Prejudice" "Le Rouge et le Noir" "War and Peace"
-->
<command name="pick" parameter="'Select a title' false %_"/>

[2] Then use another XPath expression to obtain the ID of the book
having the title chosen by the user. Something like:

<get expression="//bo...@title='%_']/@id"/>


Reply via email to