xsl-list
[Top] [All Lists]

RE: Problem with xsl:if

2004-04-21 09:44:19
-----Original Message-----
From: Gerald Fingerlos [mailto:gerald(_at_)fingerlos(_dot_)at]



Hi,

<snip />
What Id like to to is the get an output document which should contain

  <add-attr attr-name="jkuPeHabd">
    <value type="string">7777-33-11</value>
  </add-attr>

only, if the jkuSLABS=90 AND jkuSLART=50. Otherwise the 3 lines should
be omitted.


Try this:

<xsl:template match="*[(_at_)attr-name='jkuPeHabd']">
  <xsl:choose>
    <xsl:when test="preceding-sibling::add-attr[
                  @attr-name='jkuSLABS'][1]/value='90' and
                preceding-sibling::add-attr[
                  @attr-name='jkuSLART'][1]/value='50'">
      <xsl:copy-of select="." />
    </xsl:when>
    <xsl:otherwise>
      <!-- do something else -->
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

I thought of the following, but I think I am misunderstanding
something:

<snip />
 <xsl:template match="*[(_at_)attr-name='jkuPeHabd']">
   <xsl:variable name="slart"
        select="//*[(_at_)attr-name='jkuPeBeschSAP22SLART']//value"/>
   <xsl:variable name="slabs"
        select="//*[(_at_)attr-name='jkuPeBeschSAP22SLABS']//value"/>

   <xsl:if test="($slart!='50')   or   ($slabs!='90')">
   </xsl:if>
 </xsl:template>

As far as I can see the if never gets true, but still if it would be
true, I would need some "else" operation. Maybe you can give me a hint
how to solve this.


AFAICT, there is something odd about the variables:

//value

all value nodes, descending (no matter what level) from

//*

any element node, at any level in the source document,

[(_at_)attr-name='jkuPeBeschSAP22SLART']

having an attribute attr-name equal to 'jku...'

I don't think that that's what you really want to compare to. In this case,
it could work, but add a few other nodes to your source document, and this
would lead to highly undesirable results.


Hope this helps!

Cheers,

Andreas



<Prev in Thread] Current Thread [Next in Thread>