Thanks a lot!
I had missed the join() extension, sorry!
I'll obviously find some way from your indications.

Alain Pierrot

Le 5 sept. 05 ? 10:51, Hussein Shafie a ?crit :

> First of all, we already have a join() XPath function. See
> http://www.xmlmind.com/xmleditor/_distrib/doc/commands/ch07s01.html
>
> Alain Pierrot wrote:
>
>> I am trying to build an user-friendly way of populating IDREFS
>> attributes which would:
>> 1) select through an XPath function the relevant targets (subset  
>> of  ids
>> to avoid scrolling the full list);
>> 2) display in a pop-up relevant information to allow the choice, i.e.
>> (calculated) content of elements rather than ids;
>> 3) allow multiple selection.
>>
>> "set-attribute-button" (http://www.xmlmind.com/xmleditor/_distrib/ 
>> doc/
>> csssupport/ch05s29.html) is restricted to the whole list of ids and
>> doesn't allow multiple selection (which makes it awkward to use with
>> IDREFS)
>> ? Is there a workaround there ?
>> ? Could multiple selection ability for set-attribute-button be  
>> added  to
>> the wish-list ?
>>
>
> This could be implemented using a command-button
> http://www.xmlmind.com/xmleditor/_distrib/doc/csssupport/ch05s06.html
> invoking a macro-command.
>
> The macro-command would:
> [1] Collect IDs using XPath-based "get" construct.
> http://www.xmlmind.com/xmleditor/_distrib/doc/commands/ch04.html
>
> [2] Use command "pick" to let the user select IDs.
> http://www.xmlmind.com/xmleditor/_distrib/doc/commands/ch06s40.html
>
> [3] set the IDREFS attribute using command "putAttribute".
> http://www.xmlmind.com/xmleditor/_distrib/doc/commands/ch06s42.html
>
> The only problen is that command "pick" does not support multiple
> selections. You'll need to write an enhanced command "pick" yourself.
> This is trivial (the source code of command "pick" is attached).
>
>
>
>
>> "list" (http://www.xmlmind.com/xmleditor/_distrib/doc/csssupport/
>> ch05s24.html) seems the best way to achieve what I wish but I can't
>> find a way to build labels and values with the actual coverage of   
>> XPath
>> 1.0.
>> ? Any idea to convert a node set into the \A separated strings "list"
>> manages ?
>>
>
> I've tested something like this and it works fine:
>
> ---
> foo {
>     content: list(attribute, bar,
>                   values, xpath("join(//@id, '\A ')"),
>                   selection, multiple,
>                   separator, " ");
> }
> ---
>
> The only problem is: how do you refresh the content of the list as the
> author adds more IDs to the document?
>
> The above approach, command-button+macro-command, is much better IMHO.
>
>
>
>
>
>> XPath 2.0 seems to offer a whole lot of facilities to enhance the
>> already very convenient support XXE provides (the "if" feature is
>> really an useful extension:-)).
>> ? Do you consider covering more features of XPath 2.0 in future   
>> releases?
>> function "for $x in" would be useful together with "string- join"
>> (http://www.w3.org/TR/xquery-operators/#func-string-join)...
>>
>
> We'll probably add more XPath extension functions in the future. These
> extension functions will be as close to their XPath 2.0 counterpart as
> possible.
>
> We do not intend to support full XPath 2.0 in the near future.  
> XPath 1.0
>  seems to be sufficient for 99% of our needs.
>
> ---
> PS: To my knowledge, "for $x in" is XQuery, not XPath 2.0.
>
> ---------------------------------------------------------------------- 
> -----------------
> Wanadoo vous informe que cet  e-mail a ete controle par l'anti- 
> virus mail.
> Aucun virus connu a ce jour par nos services n'a ete detecte.
>
> /*
>  * Copyright (c) 2002-2005 Pixware.
>  *
>  * Author: Hussein Shafie
>  *
>  * This file is part of the XMLmind XML Editor project.
>  * For conditions of distribution and use, see the accompanying  
> legal.txt file.
>  */
> package com.xmlmind.xmleditapp.command;
>
> import java.io.IOException;
> import java.io.InputStreamReader;
> import java.io.LineNumberReader;
> import java.io.File;
> import java.net.MalformedURLException;
> import java.net.URL;
> import java.net.URLConnection;
> import java.util.ArrayList;
> import java.awt.Component;
> import com.xmlmind.xmledit.util.MiscUtil;
> import com.xmlmind.xmledit.util.StringUtil;
> import com.xmlmind.xmledit.util.FileUtil;
> import com.xmlmind.xmledit.guiutil.Alert;
> import com.xmlmind.xmledit.guiutil.LabeledValue;
> import com.xmlmind.xmledit.guiutil.ItemChooserDialog;
> import com.xmlmind.xmledit.gadget.Gadget;
> import com.xmlmind.xmledit.view.DocumentView;
> import com.xmlmind.xmledit.command.RecordableCommand;
>
> public class Pick extends RecordableCommand {
>     private String[] args = null;
>
>     public boolean prepareCommand(Gadget gadget,
>                                   String parameter, int x, int y) {
>         args = null;
>
>         DocumentView docView = (DocumentView) gadget;
>         if (docView.getDocument() == null)
>             return false;
>
>         if (parameter == null)
>             return false;
>
>         args = StringUtil.splitArguments(parameter);
>         return (args.length >= 3);
>     }
>
>     protected Object doExecuteCommand(DocumentView docView,
>                                       String parameter, int x, int  
> y) {
>         Component parentComponent = docView.getPanel();
>
>         String title = args[0];
>         boolean labelValuePairs = "true".equals(args[1]);
>
>         String[] strings = args;
>         int offset = 2;
>         int count = args.length - 2;
>
>         if (count == 3 && "@".equals(args[2])) {
>             String[] content;
>             try {
>                 content = loadFile(args[3], args[4]);
>             } catch (IOException e) {
>                 Alert.showError(parentComponent,
>                 Msg.msg("PICK.cannotLoadFile",
>                     args[3], MiscUtil.reason(e)));
>                 return EXECUTION_FAILED;
>             }
>
>             strings = content;
>             offset = 0;
>             count = content.length;
>         }
>
>         LabeledValue[] items;
>         int widest = 0;
>         if (labelValuePairs) {
>             items = new LabeledValue[count/2];
>
>             int j = 0;
>             count = offset + 2*(count/2);
>             for (int i = offset; i < count; i += 2) {
>                 String label = strings[i];
>
>                 int length = label.length();
>                 if (length > widest)
>                     widest = length;
>
>                 items[j++] = new LabeledValue(label, strings[i+1]);
>             }
>         } else {
>             items = new LabeledValue[count];
>
>             int j = 0;
>             count = offset + count;
>             for (int i = offset; i < count; ++i) {
>                 String value = strings[i];
>
>                 int length = value.length();
>                 if (length > widest)
>                     widest = length;
>
>                 items[j++] = new LabeledValue(value);
>             }
>         }
>
>         int rows = items.length;
>         if (rows < 10)
>             rows = 10;
>         else if (rows > 30)
>             rows = 30;
>
>         int columns = widest;
>         if (columns < 10)
>             columns = 10;
>         else if (columns > 60)
>             columns = 60;
>
>         ItemChooserDialog chooser =
>             new ItemChooserDialog(parentComponent, title, rows,  
> columns);
>         chooser.setSingleClick(true);
>
>         LabeledValue chosen = (LabeledValue) chooser.chooseItem 
> (items);
>         return (chosen == null)? EXECUTION_FAILED : chosen.value;
>     }
>
>     private static final String[] loadFile(String fileName, String  
> encoding)
>         throws IOException {
>         if ("default".equals(encoding))
>             encoding = FileUtil.defaultEncoding();
>
>         URL url = null;
>         try {
>             url = new URL(fileName);
>         } catch (MalformedURLException ignored) {}
>
>         if (url == null) {
>             File file = new File(fileName);
>             if (file.isFile())
>                 url = FileUtil.fileToURL(file);
>         }
>
>         if (url == null)
>             throw new IOException(Msg.msg("PICK.notAFileName",  
> fileName));
>
>         return doLoadFile(url, encoding);
>     }
>
>     private static final String[] doLoadFile(URL url,
>                                              String encoding)
>         throws IOException {
>         URLConnection connection = url.openConnection();
>         connection.setUseCaches(false);
>         connection.setIfModifiedSince(0);
>
>         LineNumberReader in = new LineNumberReader(
>             new InputStreamReader(connection.getInputStream(),  
> encoding));
>
>         ArrayList list = new ArrayList();
>         String line;
>
>         try {
>             while ((line = in.readLine()) != null) {
>                 if (line.length() > 0)
>                     list.add(line);
>             }
>         } finally {
>             in.close();
>         }
>
>         String[] lines = new String[list.size()];
>         list.toArray(lines);
>         return lines;
>     }
> }
>
> --
> XMLmind XML Editor Support List
> xmleditor-support at xmlmind.com
> http://www.xmlmind.com/mailman/listinfo/xmleditor-support



Reply via email to