Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Trying to use count() on subset of nodes
Trying to use count() on subset of nodes [message #16941] Fri, 18 May 2007 21:01 Go to next message
Eclipse UserFriend
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 #17094 is a reply to message #16941] Tue, 22 May 2007 14:09 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
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


"Bernard Farrell" <bernard.farrell@gmail.com> wrote in message
news:2400e9deed69d5b16844e82b6653b405$1@www.eclipse.org...
>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 Go to previous messageGo to next message
Eclipse UserFriend
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?
Re: Trying to use count() on subset of nodes [message #17152 is a reply to message #17123] Wed, 23 May 2007 12:17 Go to previous message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Bernard:

Glad you solved this. Once the Europa release is out of the way, I'm
thinking of starting a JET FAQ.

I'll post an announcement to the newsgroup once I've got the infrastructure
in place.

Paul

"Bernard Farrell" <bernard.farrell@gmail.com> wrote in message
news:94814c63aec2f9c2f591a3f10489dd62$1@www.eclipse.org...
> 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?
>
>
Previous Topic:Using AND in a test
Next Topic:Code generation for the UML
Goto Forum:
  


Current Time: Sat Apr 20 04:16:55 GMT 2024

Powered by FUDForum. Page generated in 0.02628 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top