Message: 8
> Date: Tue, 15 Dec 2009 14:23:31 +0100
> From: Hussein Shafie <hussein at xmlmind.com>
> Subject: Re: [XXE] Using XPath to create arguments to pick    command
>       dynamically
> To: Mariusz Idzikowski <m.idzikowski at lexicode.pl>
> Cc: "xmleditor-support at xmlmind.com" <xmleditor-support at xmlmind.com>
> Message-ID: <4B278DD3.4050409 at xmlmind.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Mariusz Idzikowski wrote:
>   
>>> [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"/>
>>>       
>> Your solution rests on the assumption that all titles in the document should 
>> be unique, which may not necessarily be the case...
>>
>> If the pick command could (optionally, of course) return the *index* of the 
>> selected item (like e.g. JList's getSelectedIndex method or similar methods 
>> of ListBox-like controls in other languages), perhaps this problem could be 
>> solved in a way similar to this:
>>
>> <set variable="ids" expression="//book/@id"/>
>> <set variable="titles" expression="concat('&quot;', join(//book/@title, 
>> '&quot; &quot;'), '&quot;')" plainString="false" />
>> <command name="pick" parameter="'Select a title' 
>> some-new-get-index-instead-of-value-parameter  $titles"/>
>> <get expression="$ids[%_]"/>       <!-- is it possible to index into a user 
>> variable? -->
>>
>> I suspect that there may be other scenarios when the pick command returning 
>> the index rather than value of the selected item could prove helpful.
>>     
>
> I don't think so. I do not remember any such scenario.
>
>
>
>   
>> Is there any hope that such a functionality could be implemented in the 
>> future?
>>
>>     
>
> I'm sorry but the answer is no. If you want something more elaborate
> that what I have suggested, I'm afraid you'll have to implement it
> yourself in Java.
>   

Another possibility is to use a transform to create what you want for 
the pick command and then feed the pick command with that.  I do that 
for a number of referenced items.  For example for citations to 
(bibliographic) references, I use these two commands

    <cfg:command name="setCitation">
        <cfg:macro>
            <cfg:sequence>
                <cfg:pass>
                    <cfg:command name="selectNode" 
parameter="self[implicitElement] citation"/>
                </cfg:pass>
                <cfg:command name="getRefWorkTitlesandIds"/>
                <cfg:command name="pick" parameter="Citation true %_"/>
                <cfg:command name="putAttribute" 
parameter="[implicitElement] ref %_"/>
            </cfg:sequence>
        </cfg:macro>
    </cfg:command>
    <cfg:command name="getRefWorkTitlesandIds">
        <cfg:process showProgress="false">
            <cfg:copyDocument to="in.xml"/>
            <cfg:transform cacheStylesheet="true" file="in.xml" 
stylesheet="../transforms/GetRefWorkTitlesAndIds.xsl" to="out.xml"/>
            <cfg:read encoding="UTF-8" file="out.xml"/>
        </cfg:process>
    </cfg:command>

and this XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
    <xsl:output method="text" encoding="UTF-8" indent="no"/>
    <xsl:template match="/">
        <xsl:apply-templates select="//refWork">
        <xsl:sort select="../@citename"/>
          <xsl:sort select="refTitle"/>
        </xsl:apply-templates>
    </xsl:template>
    <xsl:template match="//refWork">
        <xsl:text>"</xsl:text>
        <xsl:value-of select="../@citename"/>
        <xsl:text>: </xsl:text>
        <xsl:apply-templates select="refTitle" mode="InTitle"/>
        <xsl:text> {</xsl:text>
        <xsl:value-of select="@id"/>
        <xsl:text>}"
</xsl:text>
        <xsl:value-of select="@id"/>
        <xsl:text>
</xsl:text>
    </xsl:template>
    <xsl:template match="object" mode="InTitle">
        <xsl:variable name="type" select="id(@type)"/>
        <xsl:value-of select="$type/@before"/>
        <xsl:value-of select="."/>
        <xsl:value-of select="$type/@after"/>
    </xsl:template>
</xsl:stylesheet>

Here is a screenshot of what the pick dialog can look like (since I'm 
not sure if graphics like this come through to the list, I'm copying 
Mariusz and Hussein):



Hope this helps,

--Andy

Reply via email to