Xpath question 2

Discussion in 'XML' started by mikael petterson, Sep 16, 2003.

  1. 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">
    mikael petterson, Sep 16, 2003
    #1
    1. Advertising

  2. In article <bk78ps$k9i$>,
    mikael petterson <> wrote:

    % 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.
    --

    Patrick TJ McPhee
    East York Canada
    Patrick TJ McPhee, Sep 17, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marvin_123456

    "Memory leak" in javax.xml.xpath.XPath

    Marvin_123456, Jul 29, 2005, in forum: Java
    Replies:
    4
    Views:
    1,969
    jan V
    Jul 29, 2005
  2. Alastair Cameron
    Replies:
    1
    Views:
    7,403
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  3. Anna
    Replies:
    0
    Views:
    520
  4. goog
    Replies:
    0
    Views:
    506
  5. Tjerk Wolterink

    XPath: efficiency in xpath expressions

    Tjerk Wolterink, Nov 13, 2004, in forum: XML
    Replies:
    1
    Views:
    1,625
    Richard Tobin
    Nov 13, 2004
Loading...

Share This Page