Topic
  • 1 reply
  • Latest Post - ‏2013-06-21T12:48:06Z by HermannSW
smashyrahul
smashyrahul
394 Posts

Pinned topic Testing multiple error condition.

‏2013-06-21T10:17:32Z |

Hello Experts,

If I want to configure XSL to test multiple error conditions in an error rule, will the below statement work properly?

<xsl:when test="dp:variable('var://service/error-code')='0x01130006' or '0x01130007' or '0x01130008 or 0x01130009'">

Or do you suggest some other method?

 

Thanks,

Rahul

  • HermannSW
    HermannSW
    4725 Posts

    Re: Testing multiple error condition.

    ‏2013-06-21T12:48:06Z  

    Hello Rahul,

    from the spec:
    http://www.w3.org/TR/xpath/#booleans

    "... If one object to be compared is a node-set and the other is a string, then the comparison will be true if and only if there is a node in the node-set such that the result of performing the comparison on the string-value of the node and the other string is true. ..."

    So you can have a nodeset of error values to compare against.

    But please cache the "error-code" value in a variable if you do access that value at many places (which your <xsl:when> suggests).
    Reason is that accessing any "dp:variable()" is much more costly than accessing a XPath VariableReference.

    So this can be what you need:

    <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:dp="http://www.datapower.com/extensions"
      extension-element-prefixes="dp"
    >
      <xsl:output omit-xml-declaration="yes" />

      <xsl:variable name="error-code"
        select="dp:variable('var://service/error-code')"
      />

      <xsl:variable name="codeset1">
        <code>0x01130006</code>
        <code>0x01130007</code>
        <code>0x01130008</code>
        <code>0x01130009</code>
      </xsl:variable>

      <xsl:template match="/">
        <xsl:value-of select="$error-code = $codeset1/*"/>
      </xsl:template>

    </xsl:stylesheet>


    In your special use case there is an alternative because of the "0x" prefixes for error codes:

      <xsl:variable name="codeset2"
        select=" '0x01130006 0x01130007 0x01130008 0x01130009' "
      />

      <xsl:template match="/">
        <xsl:value-of select="contains($codeset2, $error-code)"/>
      </xsl:template>

     

    Hermann<myXsltBlog/> <myXsltTweets/> <myCE/>

    Updated on 2013-06-21T12:53:08Z at 2013-06-21T12:53:08Z by HermannSW