You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Sanjay Gupta <sa...@cisco.com> on 2002/09/05 02:40:11 UTC

XSL question

Hi,

I am trying to write a XSL and I want to use if-else kind of statement
inside a for loop.
How can I test for a node not being present.

Here is a sample XML-

<company>
<eng> M1</eng>
<secr> S1</secr>
<mgr> mg1</mgr>
...
<ceo> c0</ceo>
</company>

Here is the psedo code I am trying to write -

for each node in <company>
 if node is NOT equal to <ceo>
  print STAFF
 else
  print OWNER

PROBLEM: How can I construct if node is NOT equal to <ceo> ? An alternate
way to do the same will also work for me.

Here is the actual XSL I am constructing -

<xsl:template match="/company">
 <xsl:for-each select="*">
   <xsl:choose>
    <xsl:when test=???????>
     <tr><td><b>Chief Exec Officer</b></td>
         <td><xsl:value-of select="."/></td></tr>
    </xsl:when>
    </xsl:otherwise>
     <tr><td><xsl:value-of select="local-name(.)"/></td>
         <td><xsl:value-of select="."/></td></tr>
    <xsl:otherwise>
  </xsl:for-each>
 </xsl:template>

Regards,
-Sanjay


Getting the type of an xpath

Posted by Richard Emberson <re...@outerharbor.com>.
So you have an xpath string and xmlschema document instances of which
you
will be applying the xpath to. What you want to know is what is the
"type"
that the xpath will return. To find it you take the xpath and navigate
the
xmlschema definition until you get to the set of nodes, node, attribute,
or
content defined by the xpath at which point you know the type.
Is there a different way of getting the type? Has anyone written a tool
for walking an xpath + xmlschema document to get to the type?

Thanks.

Richard


Re: XSL question

Posted by "Frank E. Weiss" <fr...@well.com>.
Or you might make use of the XPath not() function.

-- Frank Weiss

Adam A R wrote:

> Hi Sanjay,
>
>  > Here is the psedo code I am trying to write -
>  >
>  > for each node in <company>
>  >  if node is NOT equal to <ceo>
>  >   print STAFF
>  >  else
>  >   print OWNER
>  >
>
> You could simply see it in a different way and your problem is
> solved.
>
> here is the psuedo code for my view
>
> for each node in <company>
>    if node is equal to <ceo>
>      print OWNER
>    else
>      print STAFF
>
> Note the reversal of test condition.
> I thought that was very easy!
>
> see if that helps you out...
>
> cheers
> Adam


Re: XSL question

Posted by Adam A R <aa...@sybase.co.jp>.
Hi Sanjay,

 > Here is the psedo code I am trying to write -
 >
 > for each node in <company>
 >  if node is NOT equal to <ceo>
 >   print STAFF
 >  else
 >   print OWNER
 >

You could simply see it in a different way and your problem is 
solved.

here is the psuedo code for my view

for each node in <company>
   if node is equal to <ceo>
     print OWNER
   else
     print STAFF

Note the reversal of test condition.
I thought that was very easy!

see if that helps you out...

cheers
Adam