468,733 Members | 1,290 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,733 developers. It's quick & easy.

XSL:IF and OR

I need to get nodes in a xml file that match one out of two
parameters...but how can I create a or statemement with <xsl:if>?

E.G
---xml--
...
<movie>
<title>T2</title>
</movie>
<movie>
<title>Bone Collector</title>
</movie>
...
---xslt---
<xsl:parameter name="myPar1"/>
<xsl:parameter name="myPar2"/>
.....
<xsl:for-each select="topnode/movie">
<xsl:if test="(title = $myPar1) OR (title = $myPar2)"> <---------
--do something
</xsl:if>
</xsl:for-each>
------------------------------
I want something like the above, but it has to check ALL of the
parameters for every title in the xml file.

Any ideas?

Jørn T
Jul 20 '05 #1
2 10511
Jørn,

I have the following test XML and XSLT documents:

*<xml>*
<root>
<node id="1">text 1</node>
<node id="2">text 2</node>
<node id="3">text 3</node>
</root>
*</xml>*

*<xslt>*
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/root">
<xsl:for-each select="node">
-<xsl:value-of select="@id" />-<br/>
<xsl:if test="@id = '1' or @id = '2'">
###<xsl:value-of select="." />###<br/><br/>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
*</xslt>*
When transformed, it produces the following results:

*<results>*
-1-
###text 1###

-2-
###text 2###

-3-
*</results>*
Is this what you're looking for?
- Larry
Jørn Tommy Kinderås wrote:
I need to get nodes in a xml file that match one out of two
parameters...but how can I create a or statemement with <xsl:if>?

E.G
---xml--
..
<movie>
<title>T2</title>
</movie>
<movie>
<title>Bone Collector</title>
</movie>
..
---xslt---
<xsl:parameter name="myPar1"/>
<xsl:parameter name="myPar2"/>
....
<xsl:for-each select="topnode/movie">
<xsl:if test="(title = $myPar1) OR (title = $myPar2)"> <---------
--do something
</xsl:if>
</xsl:for-each>
------------------------------
I want something like the above, but it has to check ALL of the
parameters for every title in the xml file.

Any ideas?

Jørn T


Jul 20 '05 #2
Larry Marburger <no@spam.com> wrote:
Jørn,
<*snip*>
Is this what you're looking for?

Yea, looks like it's the newline char that gets passed with the
parameters that makes the xsl:if stop working. I guess that "Test" is
not the same as "Test\n".

Jørn T
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by LisaDi | last post: by
9 posts views Thread by Andrea Maschio | last post: by
3 posts views Thread by Eric Theil | last post: by
5 posts views Thread by Luke Vogel | last post: by
1 post views Thread by Fred | last post: by
4 posts views Thread by Doulos05 | last post: by
4 posts views Thread by grbeal | last post: by
3 posts views Thread by z1 | last post: by
1 post views Thread by CARIGAR | last post: by
xarzu
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.