Layer7 API Management

  • 1.  Convert a string to lowercase/uppercase

    Posted Mar 10, 2017 12:47 PM

    Hi,

     

    I want to convert a string value saved in context_variable into lowercase/uppercase.

    Can you please suggest how to transform.

     

    I tried regular expression, but I was not able to convert.

     

    Thanks,

    Ravish



  • 2.  Re: Convert a string to lowercase/uppercase

    Broadcom Employee
    Posted Mar 10, 2017 12:51 PM

    Hi Ravish4596,

     

    This article should help with enforcing case: 

     

    Enforcing character case in a context variable or string 

     

    Regards,

    Joe



  • 3.  Re: Convert a string to lowercase/uppercase

    Posted Mar 10, 2017 01:12 PM

    Hi Joe,

     

    I got this error while using XSL Transformation:

    Message not XML, cannot perform XSL trasformation.

     

    Regards,

    Ravish



  • 4.  Re: Convert a string to lowercase/uppercase

    Posted Mar 10, 2017 05:03 PM

    Ravish,

    Did you get an error using the example policy or your own policy? Send us more details on what you are using.



  • 5.  Re: Convert a string to lowercase/uppercase
    Best Answer

    Posted Mar 11, 2017 12:14 AM

    Hi Mohindra,

     

    I used the same example policy and got error.

    I have a context variable "cv_Name" with value "Ravish Kumar".

    I want to convert this value to "ravish kumar" (all in lower case).

     

    I tried xsl transformation:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output omit-xml-declaration="yes"/>
        <xsl:param name="cv_Name"/>
        <xsl:template match="/">

            <xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'"/>
            <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
            <xsl:value-of select="translate($cv_Name,$uppercase,$lowercase)"/>        
        </xsl:template>
    </xsl:stylesheet>

     

    But I got an error: "Message not XML, cannot perform XSL trasformation".

     

    Thanks,

    Ravish



  • 6.  Re: Convert a string to lowercase/uppercase

    Broadcom Employee
    Posted Mar 12, 2017 06:34 PM

    For all the messages, ensure their content-type is text/xml



  • 7.  Re: Convert a string to lowercase/uppercase

    Posted Mar 08, 2019 12:52 AM

    Hi Joe,

     

    I have tried the same and referred the link you shared. But I'm getting the same error as Ravish.

     

    Initially, I have set a context variable (var_1) to "Anushka10" as a message type (text/xml).

     

    Then applied the below XSL Transformation- 

        <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:output omit-xml-declaration="yes"/>
       <xsl:param name="foo"/>
       <xsl:template match="/">
       <xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'"/>
       <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
       <xsl:value-of select="translate($foo,$uppercase,$lowercase)"/>
       </xsl:template>
       </xsl:stylesheet>

     

    Regards,

    Anushka



  • 8.  Re: Convert a string to lowercase/uppercase

    Posted Mar 08, 2019 12:57 AM

    Hi Anushka,

     

    Can you please show me the errors what are you getting.

     

    Regards,

    Ravish



  • 9.  Re: Convert a string to lowercase/uppercase

    Broadcom Employee
    Posted Mar 10, 2019 05:34 PM

    I would recommend xpath 2.0, rather than xslt,

    xpath expression: lower-case($orgstr)

     

    Sample policy,

    <?xml version="1.0" encoding="UTF-8"?>
    <wsp:Policy xmlns:L7p="http://www.layer7tech.com/ws/policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2002/12/policy">
        <wsp:All wsp:Usage="Required">
            <L7p:SetVariable>
                <L7p:Base64Expression stringValue="PGEvPg=="/>
                <L7p:ContentType stringValue="text/xml; charset=utf-8"/>
                <L7p:DataType variableDataType="message"/>
                <L7p:VariableToSet stringValue="a"/>
            </L7p:SetVariable>
            <L7p:SetVariable>
                <L7p:Base64Expression stringValue="QUJjZCBFRiBNYXJr"/>
                <L7p:VariableToSet stringValue="orgstr"/>
            </L7p:SetVariable>
            <L7p:ResponseXpathAssertion>
                <L7p:VariablePrefix stringValue="lowercase"/>
                <L7p:XmlMsgSrc stringValue="a"/>
                <L7p:XpathExpression xpathExpressionValue="included">
                    <L7p:Expression stringValue="lower-case($orgstr)"/>
                    <L7p:Namespaces mapValue="included">
                        <L7p:entry>
                            <L7p:key stringValue="s"/>
                            <L7p:value stringValue="http://schemas.xmlsoap.org/soap/envelope/"/>
                        </L7p:entry>
                    </L7p:Namespaces>
                    <L7p:XpathVersion xpathVersion="XPATH_2_0"/>
                </L7p:XpathExpression>
            </L7p:ResponseXpathAssertion>
            <L7p:HardcodedResponse>
                <L7p:Base64ResponseBody stringValue="JHtsb3dlcmNhc2UucmVzdWx0c1swXX0="/>
                <L7p:ResponseContentType stringValue="text/plain; charset=UTF-8"/>
            </L7p:HardcodedResponse>
        </wsp:All>
    </wsp:Policy>


  • 10.  Re: Convert a string to lowercase/uppercase

    Posted Sep 07, 2018 03:20 PM

    this is very helpful