if conditions

E

Eliza Zadura

I have the following loops:

<xsl:for-each
select="//node[@type='N_MICROFLOW_SD'][@display=$microflow_id]">
<xsl:variable name="sd_id" select="./@object"/>
<xsl:variable name="doc_id"
select="//link[@type='L_DC_SD'][@to=$sd_id]/@from"/>

<xsl:if test="//link[@type='L_MICROFLOW_WA_SD'][@to=$sd_id]/@from!=''">
<tr>
<td>Output:</td>
<td>
<xsl:value-of select="//object[@id=$sd_id]/property[@name='SDMSGNAM']"/>
<xsl:text> - </xsl:text>
<xsl:value-of select="//object[@id=$doc_id]/property[@name='ACNAME']"/>
</td>
</tr>
</xsl:if>

</xsl:for-each>

<xsl:for-each
select="//node[@type='N_MICROFLOW_SD'][@display=$microflow_id]">
<xsl:variable name="sd_id" select="./@object"/>
<xsl:variable name="doc_id"
select="//link[@type='L_DC_SD'][@to=$sd_id]/@from"/>

<xsl:if test="//link[@type='L_WC_SD'][@to=$sd_id]/@from!=''">
<tr>
<td>Output:</td>
<td>
<xsl:value-of select="//object[@id=$sd_id]/property[@name='SDMSGNAM']"/>
<xsl:text> - </xsl:text>
<xsl:value-of select="//object[@id=$doc_id]/property[@name='ACNAME']"/>
</td>
</tr>
</xsl:if>

</xsl:for-each>

The only difference between them is that the first one checks one type
of <link> element (row 7), and the other another type (row 26). Can I do
this with one loop and one if-condition? Basically, is there an or? I
sure can't seem to find a way, but then again it is late in the
afternoon and I'm tired...
 
M

Martin Boehm

I have the following loops:

[...snip...]

The only difference between them is that the first one checks one type
of <link> element (row 7), and the other another type (row 26). Can I
do this with one loop and one if-condition? Basically, is there an
or?

There is no "else", but a kind of "switch":

---XSL Fragment---------------------------------------------------------
<xsl:choose>
<xsl:when
test="//link[@type='L_MICROFLOW_WA_SD'][@to=$sd_id]/@from!=''">
<!-- do one thing -->
</xsl:when>
<xsl:when test="//link[@type='L_WC_SD'][@to=$sd_id]/@from!=''">
<!-- do some other thing -->
</xsl:when>
<xsl:eek:therwise>
<!-- do something completely different-->
</xsl:eek:therwise>
</xsl:choose>
 
E

Eliza Zadura

Thanks Martin. That doesn't quite do the trick though. What I'm looking
for is a construct that will allow me to do the following (in
pseudocode):

If the link of TYPE or TYPE where the attribute TO is ID exists then

do something.

The crux is that if both exist, I want it done only once.

For - if - break I suppose. Can this be done with xsl?
 
M

Martin Boehm

Thanks Martin. That doesn't quite do the trick though. What I'm
looking for is a construct that will allow me to do the following (in
pseudocode):

If the link of TYPE or TYPE where the attribute TO is ID exists then
do something.

OIC. Maybe you should post a XML fragment to work with. Because your
select="//....." is very unspecific it quite difficult to picture your
XML structure.

It could solve your problem to select the nodes in question with
someting like
select="//link[@type='TYPE_1' or @type='TYPE_2']"
and use "position() = 1" to test for the first node in the resulting
node-set.
If this set has two nodes or more, e.g. both types exist, the <!-- do
something --> part is nevertheless executed only once.

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,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top