Xpath question 2

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mikael petterson

    #1

    Xpath question 2

    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_DISABL ED". Then my reasoning is the following:

    I need to climb 2 levels in order to get on the same level as
    <noNotificati on/>, <nonPersisten t/>,<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(mandato ry)">
    <xsl:text>"mand atory";</xsl:text>
    </xsl:when>
    <xsl:otherwis e>
    <xsl:text>"opti onal";</xsl:text>
    </xsl:otherwise>
    </xsl:choose>


    This is part of xsl
    =============
    <attribute name="bbBusStat e">
    <description> </description>
    <noNotificati on/>
    <nonPersisten t/>
    <readOnly/>
    <dataType>
    <enumRef name="TxDeviceG roup_BbBusState ">
    <defaultValue>B US_DISABLED</defaultValue>
    </enumRef>
    </dataType>
    </attribute>
    <attribute name="tpcMode">


  • Patrick TJ McPhee

    #2
    Re: Xpath question 2

    In article <bk78ps$k9i$1@n ewstree.wise.ed t.ericsson.se>,
    mikael petterson <mikaelpetterso n@noreply.com> wrote:

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

    [...]

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

    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
    ptjm@interlog.c om

    Comment

    Working...