Trying to use count() on subset of nodes [message #16941] |
Fri, 18 May 2007 21:01 |
Eclipse User |
|
|
|
Originally posted by: bernard.farrell.gmail.com
I have a set of nodes like the following:
....
<page name="AtionName">
<form action="dataForm">
<label type="field" name="description">
<input type="textarea" />
</label>
<label type="field" name="startdate">
<input type="dateselector" required="false"/>
</label>
</form>
</page>
And I'm trying to output code if any of the nodes have the type set to
'textarea'.
I wanted to use the count() function, but before I even get there, using
square brackets seems to choke the system.
<cc:setVariable select="$page/form/label/input/[@type='textarea']"
var="tfields" />
<cc:setVariable select="count($tfields)" var="numfields" />
I get an unrecognized token '[' on the first line above. It's two lines
because the expression in the first line seems to cause an error when
enclosed in the count() on the second line.
Now later in the same file I'm using this expression:
<cc:iterate select="$page/form/label[@type='field']" var="field">
with no problem.
What am I doing wrong here?
|
|
|
|
Re: Trying to use count() on subset of nodes [message #17123 is a reply to message #17094] |
Tue, 22 May 2007 20:38 |
Eclipse User |
|
|
|
Originally posted by: bernard.farrell.gmail.com
Paul
Thanks, we figured that out here yesterday. A fresh set of eyes helped a
lot. It would be great if there was an article (I'm thinking of writing
one myself) that shows how to solve common JET templating challenges with
sample expressions.
In the end, I just wrote the expression as:
<cc:if test="$page/form/label/input[@type='textarea']">
which a colleague pointed out worked (for my purposes) just as easily as:
<cc:if test="count($page/form/label/input[@type='textarea']) > 0">
(And I'm using cc: because the tags are in a .jsp template file.
Bernard
Paul Elder wrote:
> Bernard:
> Sometimes the simplest solutions elude you - I looked at this for 30 minutes
> before seeing it :-).
> Your first XPath expression should be:
> $page/form/label/input[@type='textarea']
> (Note the slash was removed after 'input'.)
> Paul
>>
>> ...
>> <page name="AtionName">
>> <form action="dataForm">
>> <label type="field" name="description">
>> <input type="textarea" />
>> </label>
>> <label type="field" name="startdate">
>> <input type="dateselector" required="false"/>
>> </label>
>> </form>
>> </page>
>>
>> And I'm trying to output code if any of the nodes have the type set to
>> 'textarea'.
>>
>> I wanted to use the count() function, but before I even get there, using
>> square brackets seems to choke the system.
>>
>> <cc:setVariable select="$page/form/label/input/[@type='textarea']"
>> var="tfields" />
>> <cc:setVariable select="count($tfields)" var="numfields" />
>>
>> I get an unrecognized token '[' on the first line above. It's two lines
>> because the expression in the first line seems to cause an error when
>> enclosed in the count() on the second line.
>>
>> Now later in the same file I'm using this expression:
>> <cc:iterate select="$page/form/label[@type='field']" var="field">
>> with no problem.
>>
>> What am I doing wrong here?
|
|
|
|
Powered by
FUDForum. Page generated in 0.03856 seconds