You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Michael Schuerig <mi...@schuerig.de> on 2005/01/23 16:51:54 UTC

[jelly] XPath to comma-separated list?

I'm a Jelly beginner and haven't yet wrapped my head around it 
completely. I'm looking for an idiomatic way to get from an XPath to a 
comma-separated list of selected values.

This is as far as I get

    <x:parse var="cf" xml="file://${configfile}" />
    <x:set var="infiles" trim="true"
      select="$cf//configs/config"/>

But then what?

Michael

-- 
Michael Schuerig               Most people would rather die than think.
mailto:michael@schuerig.de                            In fact, they do.
http://www.schuerig.de/michael/                      --Bertrand Russell

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


RE: [jelly] XPath to comma-separated list?

Posted by Hans Gilde <hg...@earthlink.net>.
Sounds like a good addition to the util TagLib.

In the mean time, the code below can be turned into a tag using the define
TagLib like this:

<j:jelly xmlns:j="jelly:core" xmlns:x="jelly:xml"
xmlns:define="jelly:define" xmlns:http="notImplementedYet">
  <define:taglib uri="textUtil">  
    <define:tag name="join">
	
	<x:parse var="beansProject" xml="${file}" />
    		<x:set var="configs" trim="true"
     		 select="$select"/>

    <j:forEach var="infile" indexVar="i" items="${configs}">
      <j:if test="${i gt 0}">
        <j:set var="inputs" value="${inputs},"/>
      </j:if>
      <j:set var="${var}" value="${inputs}${infile.text}"/>
    </j:forEach>

    </define:tag>
  </define:taglib>    
</j:jelly>

And then used like this:


<j:include uri="./myTagLib.jelly"/>
<textUtil:join file="<file>" select="<select>" var="<var>" />

I haven't tested this, so I might have made a coding error, but you get the
idea.

Hans

-----Original Message-----
From: marc & lan [mailto:marclan@free.fr] 
Sent: Sunday, January 23, 2005 4:40 PM
To: Jakarta Commons Users List
Subject: Re: [jelly] XPath to comma-separated list?

> Right now I'm using this code
>
>     <x:parse var="beansProject" xml="${f}" />
>     <x:set var="configs" trim="true"
>       select="$beansProject/beansProjectDescription/configs/config"/>
>
>     <j:forEach var="infile" indexVar="i" items="${configs}">
>       <j:if test="${i gt 0}">
>         <j:set var="inputs" value="${inputs},"/>
>       </j:if>
>       <j:set var="inputs" value="${inputs}${infile.text}"/>
>     </j:forEach>
>
> But for my taste this is much too pedestrian.

Sure it's no very pretty.
But I've searched for a "implode" php-like in Java, and there's not.
You can create a java class with a static method which does it

I'm thinking we need a set of text manipulation set inluding such a feature
<implode source="${src}" var="dest" sep=","/>

Marc
- 


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [jelly] XPath to comma-separated list?

Posted by marc & lan <ma...@free.fr>.
> Right now I'm using this code
>
>     <x:parse var="beansProject" xml="${f}" />
>     <x:set var="configs" trim="true"
>       select="$beansProject/beansProjectDescription/configs/config"/>
>
>     <j:forEach var="infile" indexVar="i" items="${configs}">
>       <j:if test="${i gt 0}">
>         <j:set var="inputs" value="${inputs},"/>
>       </j:if>
>       <j:set var="inputs" value="${inputs}${infile.text}"/>
>     </j:forEach>
>
> But for my taste this is much too pedestrian.

Sure it's no very pretty.
But I've searched for a "implode" php-like in Java, and there's not.
You can create a java class with a static method which does it

I'm thinking we need a set of text manipulation set inluding such a feature
<implode source="${src}" var="dest" sep=","/>

Marc
- 


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [jelly] XPath to comma-separated list? (Patch)

Posted by Michael Schuerig <mi...@schuerig.de>.
On Thursday 27 January 2005 04:11, Dion Gillard wrote:
> Could you move it over please?

http://issues.apache.org/jira/browse/JELLY-200

M.
-- 
Michael Schuerig                       All good people read good books
mailto:michael@schuerig.de                Now your conscience is clear
http://www.schuerig.de/michael/ --Tanita Tikaram, Twist In My Sobriety

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [jelly] XPath to comma-separated list? (Patch)

Posted by Dion Gillard <di...@gmail.com>.
Please don't put bugs/fixes into bugzilla.

Jelly uses http://issues.apache.org/jira/secure/BrowseProject.jspa?id=10012
for it's issue tracking.

Could you move it over please?


On Thu, 27 Jan 2005 02:30:38 +0100, Michael Schuerig
<mi...@schuerig.de> wrote:
> On Monday 24 January 2005 01:42, Paul Libbrecht wrote:
> 
> > Have a look in the code at:
> > jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/SetTag.java
> > In there you'll see a method setAsString which sets a flag (so you
> > can use the attribute "asString='true'").
> > That flag currently implies "single='true'" but that could be changed
> > to suit exactly what you wish: as string should not only convert one
> > result to string but a comma (or "${separator}") separated list.
> 
> Unfortunately, changing this breaks one of the original tests.
> 
> What makes things like this difficult is not the algorithmic part, but
> rather getting to terms with the build and test environment.
> 
> > Willing to give a try ?
> > It looks easily doable to me.
> 
> Patch at
> http://issues.apache.org/bugzilla/show_bug.cgi?id=33259
> 
> Michael
> 
> --
> Michael Schuerig                  Failures to use one's frontal lobes
> mailto:michael@schuerig.de        can result in the loss of them.
> http://www.schuerig.de/michael/   --William H. Calvin
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 


-- 
http://www.multitask.com.au/people/dion/

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [jelly] XPath to comma-separated list? (Patch)

Posted by Michael Schuerig <mi...@schuerig.de>.
On Monday 24 January 2005 01:42, Paul Libbrecht wrote:

> Have a look in the code at:
> jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/SetTag.java
> In there you'll see a method setAsString which sets a flag (so you
> can use the attribute "asString='true'").
> That flag currently implies "single='true'" but that could be changed
> to suit exactly what you wish: as string should not only convert one
> result to string but a comma (or "${separator}") separated list.

Unfortunately, changing this breaks one of the original tests.

What makes things like this difficult is not the algorithmic part, but 
rather getting to terms with the build and test environment.

> Willing to give a try ?
> It looks easily doable to me.

Patch at
http://issues.apache.org/bugzilla/show_bug.cgi?id=33259

Michael

-- 
Michael Schuerig                  Failures to use one's frontal lobes
mailto:michael@schuerig.de        can result in the loss of them.
http://www.schuerig.de/michael/   --William H. Calvin

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [jelly] XPath to comma-separated list?

Posted by Paul Libbrecht <pa...@activemath.org>.
Michael,

Have a look in the code at:
jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/SetTag.java
In there you'll see a method setAsString which sets a flag (so you can  
use the attribute "asString='true'").
That flag currently implies "single='true'" but that could be changed  
to suit exactly what you wish: as string should not only convert one  
result to string but a comma (or "${separator}") separated list.

Willing to give a try ?
It looks easily doable to me.

paul


Le 23 janv. 05, à 21:03, Michael Schuerig a écrit :

> On Sunday 23 January 2005 20:37, marc & lan wrote:
>> Michael Schuerig wrote:
>>> I'm a Jelly beginner and haven't yet wrapped my head around it
>>> completely. I'm looking for an idiomatic way to get from an XPath
>>> to a comma-separated list of selected values.
>>>
>>> This is as far as I get
>>>
>>>    <x:parse var="cf" xml="file://${configfile}" />
>>>    <x:set var="infiles" trim="true"
>>>      select="$cf//configs/config"/>
>>>
>>> But then what?
>>
>> Coul you give us concret file please ? Do you have several
>> configs/config nodes ? It's these values you want to set as
>> comma-separated values ?
>
> From a file with these contents
>
> <beansProjectDescription>
>   <configs>
>     <config>src/main/webapp/WEB-INF/applicationContext1.xml</config>
>     <config>src/main/webapp/WEB-INF/applicationContext2.xml</config>
>   </configs>
> </beansProjectDescription>
>
> I want to extract a string with this content
> "src/main/webapp/WEB-INF/applicationContext1.xml,src/main/webapp/WEB- 
> INF/applicationContext".xml"
>
> Right now I'm using this code
>
>     <x:parse var="beansProject" xml="${f}" />
>     <x:set var="configs" trim="true"
>       select="$beansProject/beansProjectDescription/configs/config"/>
>
>     <j:forEach var="infile" indexVar="i" items="${configs}">
>       <j:if test="${i gt 0}">
>         <j:set var="inputs" value="${inputs},"/>
>       </j:if>
>       <j:set var="inputs" value="${inputs}${infile.text}"/>
>     </j:forEach>
>
> But for my taste this is much too pedestrian.
>
> Michael
>
> -- 
> Michael Schuerig                 Not only does lightning not strike
> mailto:michael@schuerig.de       twice, it usually doesn't strike once.
> http://www.schuerig.de/michael/  --Salman Rushdie, Fury
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [jelly] XPath to comma-separated list?

Posted by Michael Schuerig <mi...@schuerig.de>.
On Sunday 23 January 2005 20:37, marc & lan wrote:
> Michael Schuerig wrote:
> > I'm a Jelly beginner and haven't yet wrapped my head around it
> > completely. I'm looking for an idiomatic way to get from an XPath
> > to a comma-separated list of selected values.
> >
> > This is as far as I get
> >
> >    <x:parse var="cf" xml="file://${configfile}" />
> >    <x:set var="infiles" trim="true"
> >      select="$cf//configs/config"/>
> >
> > But then what?
>
> Coul you give us concret file please ? Do you have several
> configs/config nodes ? It's these values you want to set as
> comma-separated values ?

From a file with these contents

<beansProjectDescription>
  <configs>
    <config>src/main/webapp/WEB-INF/applicationContext1.xml</config>
    <config>src/main/webapp/WEB-INF/applicationContext2.xml</config>
  </configs>
</beansProjectDescription>

I want to extract a string with this content 
"src/main/webapp/WEB-INF/applicationContext1.xml,src/main/webapp/WEB-INF/applicationContext".xml"

Right now I'm using this code

    <x:parse var="beansProject" xml="${f}" />
    <x:set var="configs" trim="true"
      select="$beansProject/beansProjectDescription/configs/config"/>

    <j:forEach var="infile" indexVar="i" items="${configs}">
      <j:if test="${i gt 0}">
        <j:set var="inputs" value="${inputs},"/>
      </j:if>
      <j:set var="inputs" value="${inputs}${infile.text}"/>
    </j:forEach>

But for my taste this is much too pedestrian.

Michael

-- 
Michael Schuerig                 Not only does lightning not strike
mailto:michael@schuerig.de       twice, it usually doesn't strike once.
http://www.schuerig.de/michael/  --Salman Rushdie, Fury

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [jelly] XPath to comma-separated list?

Posted by marc & lan <ma...@free.fr>.
Michael Schuerig wrote:
> I'm a Jelly beginner and haven't yet wrapped my head around it
> completely. I'm looking for an idiomatic way to get from an XPath to a
> comma-separated list of selected values.
>
> This is as far as I get
>
>    <x:parse var="cf" xml="file://${configfile}" />
>    <x:set var="infiles" trim="true"
>      select="$cf//configs/config"/>
>
> But then what?
>

Coul you give us concret file please ? Do you have several configs/config 
nodes ? It's these values you want to set as comma-separated values ?

Marc DeXeT
-  You love camembert, vines and jelly ? ==> 
http://jelly.fr.free.fr/index.php - 


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org