Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Checking if a tag exists
Checking if a tag exists [message #6540] Fri, 23 March 2007 16:24 Go to next message
Eclipse User
Originally posted by: evaandoli.dodo.com.au

Is it possible to check whether a tag exists in the file ?
something like
<c:when exists $node/@name>

.. . . blah blah

</when>
Re: Checking if a tag exists [message #6581 is a reply to message #6540] Sun, 25 March 2007 05:45 Go to previous messageGo to next message
Eclipse User
Originally posted by: evaandoli.dodo.com.au

Ok after a few days !!!
I came up with this:-
<c:setVariable select="cardinality($action/@rightOperand , 0)"
var="hasRightOperand"/>

<c:when test="$hasRightOperand">

.. . .. insert exist code to perform . . ..

</c:when>

<c:otherwise>

....... insert otherwise code to peroform. . ..

</c:otherwise>

</c:choose>

"Stu" <evaandoli@dodo.com.au> wrote in message
news:eu0v03$afr$1@utils.eclipse.org...
> Is it possible to check whether a tag exists in the file ?
> something like
> <c:when exists $node/@name>
>
> . . . blah blah
>
> </when>
>
>
Re: Checking if a tag exists [message #6637 is a reply to message #6540] Mon, 26 March 2007 12:23 Go to previous message
Paul Elder is currently offline Paul Elder
Messages: 849
Registered: July 2009
Senior Member
Stu:

It's easier than you think. XPath has rules for turning any value into a
boolean (here's a link to the XPath 'boolean' function:
http://www.w3.org/TR/xpath#function-boolean).

What you need:

<c:when test="$node/@name">

According to XPath, the expression '$node/@name' returns a NodeSet (in this
case, a set of Attribute nodes). If the attribute is not set, the NodeSet is
empty. XPath converts a NodeSet to boolean based on the cardinality of the
NodeSet. Anything larger than zero implies true, zero implies false.

Paul

"Stu" <evaandoli@dodo.com.au> wrote in message
news:eu0v03$afr$1@utils.eclipse.org...
> Is it possible to check whether a tag exists in the file ?
> something like
> <c:when exists $node/@name>
>
> . . . blah blah
>
> </when>
>
>
Previous Topic:Re: New to JET can't access xsi:type value
Next Topic:Re: JET2 - declaring custom tags
Goto Forum:
  


Current Time: Fri Oct 24 07:20:38 GMT 2014

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

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