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

M

Martin Buchleitner

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
 
M

Moody

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 said:
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
 
M

martin buchleitner

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
 
M

Moody

I'm sorry, but it isn't working

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


martin buchleitner said:
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
 
H

Heide Ebert

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





I'm sorry, but it isn't working

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

martin buchleitner said:
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
 
B

Bill Sneddon

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



I'm sorry, but it isn't working

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


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
 
M

Moody

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 said:
I'm sorry, but it isn't working

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


martin buchleitner said:
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
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top