none
XSL Help required RRS feed

  • Question

  • Hi All,

    I have requirement where i need to check if the value of an element in the incoming message is numeric or alphanumeric. If it is alphanumeric, i must strip off the first character in the string else i just need to pass the string as it is. Can somebody tell me how to do this in XSL. It is urgent. Please respond soon.

    Thanks in advance.

    Monday, February 7, 2011 8:40 PM

Answers

  • Hi Sriram and la Cour,

     

    Thanks for your replies. I tried to figure out a way for doing it in xsl however since it was a time constraint, I wrote a simple C# class and referenced inside of my xslt to do what i wanted it to do. I tried doing using functoids and it did work for me. However we are using XSLT so i had to do it that way.

    Thanks again. 

    Thursday, February 10, 2011 2:28 PM

All replies

  • You can use the following template:

     

      <xsl:template name="StripNonNumeric">

        <xsl:param name="input" />

        <xsl:choose>

          <xsl:when test="number($input) = number($input)">

            <xsl:value-of select="$input" />

          </xsl:when>

          <xsl:otherwise>

            <xsl:value-of select="substring($input,2)" />

          </xsl:otherwise>

        </xsl:choose>

      </xsl:template>

     

    And when you need to call the template use:

     

    <MyDestNumberField>

          <xsl:call-template name="StripNonNumeric">

            <xsl:with-param name="input" select="MySourceCandidateNumberField" />

          </xsl:call-template>

    </MyDestNumberField>


    Morten la Cour

    Tuesday, February 8, 2011 7:54 AM
  • Hi,

    Are you trying to do this on a map? If so, this can be achieved with functoids only as follows.If it is a XSL need in particular, go for la Cour's way.

    Logical Numeric Functoid - to check for numeric.

    Value mapping functoid - to Pass the value if its numeric(Linked from Logical Numeric and Source Field)

    Logical NOT - To invert the Logical Numeric value and pass to another Value Mapping functoid(takes Logical Numerics input a

    Source Field1 -> Logical Numeric 1-> ValueMapping 1(Source Field as Second Input) -> Destiantion Field1           

                               Logical Numeric 1-> Logical NOT  1 -> Value Mapping 2 ->Destination Field1

    Source Field1->            String Size -> String Extract -> Value Mapping 2   

    Note: String Extract takes (SourceField,2,StringSize) as the three parameters. And '2' is the position indicator that strips the first charater off.

    Thanks.

    Please mark this as answered if it helps.

    http://srirambiztalks.wordpress.com


    Sriram N
    • Proposed as answer by SriramNarayanan Thursday, February 10, 2011 10:06 PM
    Thursday, February 10, 2011 4:38 AM
  • Hi Sriram and la Cour,

     

    Thanks for your replies. I tried to figure out a way for doing it in xsl however since it was a time constraint, I wrote a simple C# class and referenced inside of my xslt to do what i wanted it to do. I tried doing using functoids and it did work for me. However we are using XSLT so i had to do it that way.

    Thanks again. 

    Thursday, February 10, 2011 2:28 PM