Xpath question 2

M

mikael petterson

Hi (again!!),

I am still a beginner in xsl :)

I need to check if the <attribute> has a child called <mandatory>. (In this
case no!).

When I try to add some xsl code I first check what the current node is by
using:

<xsl:value-of select="."/>

The value I get is "BUS_DISABLED". Then my reasoning is the following:

I need to climb 2 levels in order to get on the same level as
<noNotification/>, <nonPersistent/>,<readOnly/> which is the same level as
where <mandatory> would have been. If <mandatory> exists add text mandatory
if not I add text optional. But I only get optional.

Any hints for the newbie ( or shall we say xsl wannabe).

//Mikael

Ps. I there a good book on xsl and xslt.

<xsl:choose>
<xsl:when test="../../boolean(mandatory)">
<xsl:text>"mandatory";</xsl:text>
</xsl:when>
<xsl:eek:therwise>
<xsl:text>"optional";</xsl:text>
</xsl:eek:therwise>
</xsl:choose>


This is part of xsl
=============
<attribute name="bbBusState">
<description></description>
<noNotification/>
<nonPersistent/>
<readOnly/>
<dataType>
<enumRef name="TxDeviceGroup_BbBusState">
<defaultValue>BUS_DISABLED</defaultValue>
</enumRef>
</dataType>
</attribute>
<attribute name="tpcMode">
 
P

Patrick TJ McPhee

% I need to check if the <attribute> has a child called <mandatory>. (In this
% case no!).

[...]

% <xsl:choose>
% <xsl:when test="../../boolean(mandatory)">

This is not a valid expression -- does it give you an error, or what?

What you want is

<xsl:when test="../../mandatory">

In a boolean context, a node set is false if it's empty, or true
otherwise.

% Ps. I there a good book on xsl and xslt.

The O'Reilly XSLT book is OK, if a bit chatty. The XPath spec isn't
too bad, especially for a W3C specification.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top