From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27208 invoked from network); 21 Aug 2001 14:03:14 -0000 Received: from sunsite.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 21 Aug 2001 14:03:14 -0000 Received: (qmail 15181 invoked by alias); 21 Aug 2001 14:03:06 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 15672 Received: (qmail 15167 invoked from network); 21 Aug 2001 14:03:04 -0000 Message-ID: <20010821140301.35191.qmail@web10404.mail.yahoo.com> Date: Tue, 21 Aug 2001 07:03:01 -0700 (PDT) From: Felix Rosencrantz Subject: XML progress To: zsh-workers MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="0-247940966-998402581=:34928" --0-247940966-998402581=:34928 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline More news from my XML experiment. I didn't have a lot of time to work on this after I last posted. Originally I intended to write some perl to help generate XML. I didn't really get started on that. I started downloading some tools for evaluation. I started playing with a windows-based editor called XSLerator. To try it out, I wrote an XSL stylesheet to convert the files I had sent last time into completion functions. (XSLerator is nice to use.) I had to make some tweaks to my original .xml to make the files consistent. But I was able to regenerate the original completion scripts. Well, almost, there were some white space differences. I also started writing XSL scripts for editting these XML files. It occured to me that if these scripts could perform editting operations on the XML it would be possible to harness the completion system to help with the creation and modification of the XML files. The completion system turns command line creation into a multiple choice quiz. It would be possible to use the completion system's documentation on demand to help guide the user, so the user wouldn't need to stare at the man page. I've attached the XSL for generating a completion function from .xml. ll I'post some XML files later in the week that can be used with it. To give you an idea, I've created a completion function for the Xalan XSLT processor (lastest Xalan Java 2) from the Apache folks. For those who are interested in size, the XML file is 2.2 times larger than the generated completion function, though about 4 times as many lines... There is no extra help or much indenting. The process I performed to get this file is listed below. XSL Scripts and XML Files attached. There is a lot of gratuitous perl code here. My feeling is that hese throw away scripts could be replaced by more general purpose tools. #Create the initial xml file. java org.apache.xalan.xslt.Process -IN null.xml -OUT xalan.xml \ -XSL new_service.xsl \ -PARAM Service "org.apache.xalan.xslt.Process" \ -PARAM Filename "_xalan" #Create a list of the flags from the help output #(flags start with '-' and are separated # by whitespace/sq brackets, or equal signs.) flags=(`java org.apache.xalan.xslt.Process| perl -ne 'chop;@w = split(/[\s\[\]=]+/); print join(" ",grep(/^-/ ,@w))," "; END{ print "\n";}' `) #Add the flags to the file. java org.apache.xalan.xslt.Process -IN xalan.xml -OUT xalan2.xml \ -XSL add_flags.xsl \ -PARAM Service "org.apache.xalan.xslt.Process" \ -PARAM Filename "_xalan" -PARAM Flags "$flags" #Get the explanations typeset -A help eval "help=(" $(java org.apache.xalan.xslt.Process | \ perl -n -e 'chop; m#\[(-\w+).*\((.*)\)#; $flag = $1;$help = $2; print "\"", $flag , "\" \"",$help,"\"\n" if ($flag ne "" && $help ne "");') ")" # Add the extracted explanations to the files. cp xalan2.xml xalan3.xml foreach f (${(k)help}) { java org.apache.xalan.xslt.Process -IN xalan3.xml \ -OUT xalan3b.xml -XSL add_explanation.xsl \ -PARAM Service "org.apache.xalan.xslt.Process" \ -PARAM Flag "$f" \ -PARAM Explanation "$help[$f]" cp xalan3b.xml xalan3.xml } #By hand to get final version of attached xalan.xml, I # did the following 1) Added descriptions and actions. 2) Prolog code, code for parameter_name state. 3) Added some missing explanations. #Generate the completion function java org.apache.xalan.xslt.Process -IN xalan3.xml \ -OUT _xalan -XSL arg.xsl Much of the manual edits could be done via XSL scripts. Though I wanted to post some of this before going much further. Also, adding the explanations was slower than I had hoped. I suspect that there is a lot of start up costs associated with the java vm, and re-parsing add_explanation.xsl. So if it was possible to batch a bunch of edits I think that would be better. I suspect the way to do this is via an XSL merge script. The idea being to create a new XML file with deltas, and have the XSL script take the master XML file and perform the edits from the new XML file. -FR. Files included: null.xml Shell XML file used by new_service.xsl new_service.xsl From null.xml creates an empty completion XML file add_flags.xsl Add the specified flags to the service file. add_explanation.xsl Add the explanation for the given Service and Flag arg.xsl Takes a completion XML file and generates ZSH func. xalan.xml The final XML file, after generation and hand edits. _xalan The generated completion function __________________________________________________ Do You Yahoo!? Make international calls for as low as $.04/minute with Yahoo! Messenger http://phonecard.yahoo.com/ --0-247940966-998402581=:34928 Content-Type: text/xml; name="send_files.txt" Content-Description: send_files.txt Content-Disposition: inline; filename="send_files.txt" cat <<'EOF_null.xml' > null.xml EOF_null.xml cat <<'EOF_new_service.xsl' > new_service.xsl EOF_new_service.xsl cat <<'EOF_add_flags.xsl' > add_flags.xsl EOF_add_flags.xsl cat <<'EOF_add_explanation.xsl' > add_explanation.xsl EOF_add_explanation.xsl cat <<'EOF_arg.xsl' > arg.xsl #compdef case $service in ) ;; esac _arguments \ : : : Service Flag Has both single and double quotes... May have a syntax with generated arguments call. ' ' ' ' " " ' ' \ * * ( ) [ ] * : : : -> (( \: )) ( ) case $state in esac ) ;; EOF_arg.xsl cat <<'EOF_xalan.xml' > xalan.xml _xalan local state line context typeset -A opt_args Input file XML file _files XSL Script XSL file _files Output file Output file _files Do not expand entity refs Quiet Pattern Conflicts Warnings Trace the templates as they are being called. Trace each generation event. Trace each selection event. Trace the template children as they are being processed. TraceListener class for trace extensions. Do stackdump on error. XML file _files -TEXT -HTML Use XML formatter and add XML header. -XML -HTML Use simple Text formatter. -XML -TEXT Use HTML formatter. Set a stylesheet parameter Parameter name parameter_name Parameter value Use line numbers for source document use media attribute to find stylesheet associated with a document. Explicitly use s2s=SAX or d2d=DOM to do transform. Transform flavor s2sSAX d2sDOM Print overall milliseconds transform took. URIResolver to be used to resolve URIs Class name _files EntityResolver to be used to resolve entities Class name _files ContentHandler to be used to serialize output Class name _files parameter_name $list_xsl EOF java org.apache.xalan.xslt.Process -IN $opt_args[-XSL] -XSL $list_xsl -OUT $param_list vars=(`cat $param_list`) rm -f $list_xsl $param_list compadd $vars fi return 0 ]]> EOF_xalan.xml cat <<'EOF__xalan' > _xalan #compdef org.apache.xalan.xslt.Process local state line context typeset -A opt_args _arguments \ '-IN:XML file:_files' \ '-XSL:XSL file:_files' \ '-OUT:Output file:_files' \ '-E[Do not expand entity refs]' \ '-QC[Quiet Pattern Conflicts Warnings]' \ '-TT[Trace the templates as they are being called.]' \ '-TG[Trace each generation event.]' \ '-TS[Trace each selection event.]' \ '-TTC[Trace the template children as they are being processed.]' \ '-TCLASS[TraceListener class for trace extensions.]' \ '-EDUMP[Do stackdump on error.]:XML file:_files' \ '(-TEXT -HTML)-XML[Use XML formatter and add XML header.]' \ '(-XML -HTML)-TEXT[Use simple Text formatter.]' \ '(-XML -TEXT)-HTML[Use HTML formatter.]' \ '*-PARAM[Set a stylesheet parameter]:Parameter name:->parameter_name:Parameter value:' \ '-L[Use line numbers for source document]' \ '-MEDIA[use media attribute to find stylesheet associated with a document.]' \ '-FLAVOR[Explicitly use s2s=SAX or d2d=DOM to do transform.]:Transform flavor:((s2s\:SAX d2s\:DOM))' \ '-DIAG[Print overall milliseconds transform took.]' \ '-URIRESOLVER[URIResolver to be used to resolve URIs]' \ '-ENTITYRESOLVER[EntityResolver to be used to resolve entities]:Class name:_files' \ '-CONTENTHANDLER[ContentHandler to be used to serialize output]:Class name:_files' case $state in parameter_name) local vars list_xsl list_xsl=/tmp/$$.list_xsl_params.xsl param_list=/tmp/$$_params.out # If the user has already specified XSL then parse that file. if (( $+opt_args[-XSL] )) ; then # $opt_args[-PARAM] ends up with a value listing all # the args to this param. separated by colons. So we get # PARAM1:param1_value:PARAM2:param2_value.... # So it should be possible to remove values from var that have # already been specified... #For now just use XSL to extract the parameter names. cat < $list_xsl EOF java org.apache.xalan.xslt.Process -IN $opt_args[-XSL] -XSL $list_xsl -OUT $param_list vars=(`cat $param_list`) rm -f $list_xsl $param_list compadd $vars fi return 0 ;; esac EOF__xalan --0-247940966-998402581=:34928--