[Laszlo-dev] Text formatting and datapaths

P T Withington ptw at pobox.com
Wed Jul 11 05:50:24 PDT 2007


Henry and I have an idea that we can leverage the new text formatting  
capabilities to simplify presentation of databindings.  We want to  
add a new formatting directive '%q' that will make an xpath query.   
The query that is made will be supplied by an extra prefix argument,  
along the lines of:  '%{firstName/text()}q'.  The 'q' directive will  
support all the usual flags regarding min/max width, padding,  
precision, etc.

So for example, the following:

     <view datapath="person/" layout="axis: x">
       <text text="$path{'firstName/text()'}" />
       <text text="$path{'lastName/text()'}" />
     </view>

might be replaced by:

     <text datapath="person/"
       ondata="format('%{firstName/text()}q %{lastName/text()}q',  
datapath, datapath)"
     />

reducing 3 nodes to 1.  Does that seem useful, or just too bizarre?   
You can already writ this as:

     <text datapath="person/"
       ondata="format('%s %s', datapath.xpathQuery('firstName/text 
()'), datapath.xpathQuery('lastNAme/text()'))"
     />

Which is only sligtly longer, but we've also thought about an  
additional step of defining a `dataformat` attribute that is a format  
control string that is used to format the data.  So the same example  
could be written even more compactly:

     <text datapath="person/"
       dataformat="'%{firstName/text()}1$q %{lastName/text()}1$q'"
     />

[The '1$' is used to access the sole implicit argument, the datapath,  
more than once.]

Is this additional formatting directive a useful idea, or should we  
just be promoting the use of `format` in `ondata`?


More information about the Laszlo-dev mailing list