Re: How to write an XSLT with several conditions (predicates)???

Discussion in 'XML' started by Martin Buchleitner, Jul 16, 2003.

  1. On Wed, 16 Jul 2003 14:41:20 GMT, "Moody" <> wrote:

    Hi!

    >
    >I know how to select certain elements of a XML by using XSLT. But I like to
    >state some extra conditions.
    >
    >Like in an addressbook, I like to see only the people, who live in Gent.
    >
    >But there is an extra difficulty, I want to place all these conditions in
    >the line, <xsl:for-each select="addressbook/customers/person">
    >and there can be more than one condition.
    >
    >So, I'll need to work with "and" and "or"....
    >


    I'd say:
    <xsl:for-each select="/addressbook/customers/person[adress[city='Gent'
    or city='Herzele']]">
    ....
    </xsl:for-each>

    will give you a node-set with person who live on Gent or in Herzele.


    HTH Martin
     
    Martin Buchleitner, Jul 16, 2003
    #1
    1. Advertising

  2. Martin Buchleitner

    Moody Guest

    Thanks, it's working great,

    but if I want to have a node-set with persons who live in Gent or in Herzele
    and whose number is 78

    I've tried a few thigs, but it won't work

    <xsl:for-each select="/addressbook/customers/person[[address[city='Gent' or
    city='Herzele']] and [address/street[@number='78']]]">

    Thanks in advance

    Jonas


    "Martin Buchleitner" <> wrote in message
    news:...
    > On Wed, 16 Jul 2003 14:41:20 GMT, "Moody" <> wrote:
    >
    > Hi!
    >
    > >
    > >I know how to select certain elements of a XML by using XSLT. But I like

    to
    > >state some extra conditions.
    > >
    > >Like in an addressbook, I like to see only the people, who live in Gent.
    > >
    > >But there is an extra difficulty, I want to place all these conditions in
    > >the line, <xsl:for-each select="addressbook/customers/person">
    > >and there can be more than one condition.
    > >
    > >So, I'll need to work with "and" and "or"....
    > >

    >
    > I'd say:
    > <xsl:for-each select="/addressbook/customers/person[adress[city='Gent'
    > or city='Herzele']]">
    > ...
    > </xsl:for-each>
    >
    > will give you a node-set with person who live on Gent or in Herzele.
    >
    >
    > HTH Martin
    >
    >
     
    Moody, Jul 16, 2003
    #2
    1. Advertising

  3. Hi!

    > <xsl:for-each
    > select="/addressbook/customers/person[[address[city='Gent'
    > or city='Herzele']] and [address/street[@number='78']]]">


    What about:
    <xsl:for-each
    select="/addressbook/customers/person[address[city='Gent' or
    city='Herzele'] and [street[@number='78']]]">

    HTH Martin




    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    martin buchleitner, Jul 16, 2003
    #3
  4. Martin Buchleitner

    Moody Guest

    I'm sorry, but it isn't working

    maybe it's impossibel to state a condition on the result of other
    conditions.???


    "martin buchleitner" <> wrote in message
    news:3f1581a2$0$198$...
    >
    > Hi!
    >
    > > <xsl:for-each
    > > select="/addressbook/customers/person[[address[city='Gent'
    > > or city='Herzele']] and [address/street[@number='78']]]">

    >
    > What about:
    > <xsl:for-each
    > select="/addressbook/customers/person[address[city='Gent' or
    > city='Herzele'] and [street[@number='78']]]">
    >
    > HTH Martin
    >
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    >
     
    Moody, Jul 16, 2003
    #4
  5. Martin Buchleitner

    Heide Ebert Guest

    Hi,

    try
    <xsl:for-each select="/addressbook/customers/person[address[city='Gent'
    or city='Herzele'][street[@number='78']]]">

    - that means: connect several predicates just by listing them. I don't
    think you can connect them by an "and".

    HTH,
    Heide Ebert






    Moody schrieb:

    > I'm sorry, but it isn't working
    >
    > maybe it's impossibel to state a condition on the result of other
    > conditions.???
    >
    > "martin buchleitner" <> wrote in message
    > news:3f1581a2$0$198$...
    > >
    > > Hi!
    > >
    > > > <xsl:for-each
    > > > select="/addressbook/customers/person[[address[city='Gent'
    > > > or city='Herzele']] and [address/street[@number='78']]]">

    > >
    > > What about:
    > > <xsl:for-each
    > > select="/addressbook/customers/person[address[city='Gent' or
    > > city='Herzele'] and [street[@number='78']]]">
    > >
    > > HTH Martin
    > >
    > >
    > >
    > >
    > > *** Sent via Developersdex http://www.developersdex.com ***
    > > Don't just participate in USENET...get rewarded for it!
    > >
     
    Heide Ebert, Jul 16, 2003
    #5
  6. Martin Buchleitner

    Bill Sneddon Guest

    I am still learning this also but you might try this.

    select="/addressbook/customers/person/address[city='Gent'
    or city='Herzele'] [street[@number='78']">

    I know you can have multiply predicates appended to each other in this
    way although not to may examples of this. I think of predicates as
    filters on the data.

    from CPU magazine article:

    XML Tools Alert: XPath VisualizerFiddling with XPath expressions can
    be relatively tough going, even with previous XSLT experience.
    Fortunately, Dimitre Novachev has created an easy browser-based tool to
    let you view XML data and see the nodes an XPath expression references.
    The tool lets you load any local XML document and enter arbitrary XPath
    expressions. In a separate frame, the tool displays a listing of the XML
    document, highlighting the nodes the XPath expression references. The
    tool is available for IE and Netscape 6+/Mozilla browsers at
    www.topxml.com/xpathvisualizer (for IE) and
    www.topxml.com/code/default.asp?p=3&id=v20021221025528 (for Netscape
    6+/Mozilla).

    Let me know if this helps.

    Bill




    Moody wrote:
    > I'm sorry, but it isn't working
    >
    > maybe it's impossibel to state a condition on the result of other
    > conditions.???
    >
    >
    > "martin buchleitner" <> wrote in message
    > news:3f1581a2$0$198$...
    >
    >>Hi!
    >>
    >>
    >>><xsl:for-each
    >>>select="/addressbook/customers/person[[address[city='Gent'
    >>>or city='Herzele']] and [address/street[@number='78']]]">

    >>
    >>What about:
    >><xsl:for-each
    >> select="/addressbook/customers/person[address[city='Gent' or
    >>city='Herzele'] and [street[@number='78']]]">
    >>
    >>HTH Martin
    >>
    >>
    >>
    >>
    >>*** Sent via Developersdex http://www.developersdex.com ***
    >>Don't just participate in USENET...get rewarded for it!
    >>

    >
    >
    >
     
    Bill Sneddon, Jul 16, 2003
    #6
  7. Martin Buchleitner

    Moody Guest

    Thanks, it is working well; both of the solutions

    So, if you put the predicates in a row ([predicates1][predicates2]), it's
    the function AND that's called (predicates1 AND predicates2).

    Is it possible to have here OR. So, we get: this set of conditions OR this
    set of conditions.

    Thanks a lot

    Jonas Andries


    "Moody" <> wrote in message
    news:eek:bgRa.15104$-ops.be...
    > I'm sorry, but it isn't working
    >
    > maybe it's impossibel to state a condition on the result of other
    > conditions.???
    >
    >
    > "martin buchleitner" <> wrote in message
    > news:3f1581a2$0$198$...
    > >
    > > Hi!
    > >
    > > > <xsl:for-each
    > > > select="/addressbook/customers/person[[address[city='Gent'
    > > > or city='Herzele']] and [address/street[@number='78']]]">

    > >
    > > What about:
    > > <xsl:for-each
    > > select="/addressbook/customers/person[address[city='Gent' or
    > > city='Herzele'] and [street[@number='78']]]">
    > >
    > > HTH Martin
    > >
    > >
    > >
    > >
    > > *** Sent via Developersdex http://www.developersdex.com ***
    > > Don't just participate in USENET...get rewarded for it!
    > >

    >
    >
    >
     
    Moody, Jul 17, 2003
    #7
    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. Alfraed
    Replies:
    0
    Views:
    828
    Alfraed
    Jul 14, 2003
  2. Soren Kuula
    Replies:
    2
    Views:
    577
    Malcolm Dew-Jones
    Apr 13, 2005
  3. Maitre Bart
    Replies:
    0
    Views:
    443
    Maitre Bart
    Oct 22, 2004
  4. Replies:
    0
    Views:
    334
  5. Trent Buck

    CPP predicates for compiler extensions

    Trent Buck, Nov 8, 2004, in forum: C Programming
    Replies:
    1
    Views:
    409
    Mark A. Odell
    Nov 8, 2004
Loading...

Share This Page