5

I am using wso2esb-4.8.1.

I wish to change my request first letter to lowercase. I am getting request parameters like this:

 <property name="Methodname" expression="//name/text()" scope="default" type="STRING"/>

In this way I am getting names like

GetDetails, CallQuerys, ChangeService...

Whereas I wish to change all the names to be like this:

getDetails, callQuerys, changeService...

If I wanted to upper or lower the case of the entire name, I could use XPath's fn:upper-case() and fn:lower-case() functions, but my requirement is different.

How can I change all the first letters only to lowercase?

Is it possible with XPath or XSLT?

Community
  • 1
  • 1
user3595078
  • 273
  • 3
  • 17
  • how can i use fn:lower-case() in an expression? using it like this: gives an error: Invalid XPath expression for attribute 'expression' – user666 Dec 16 '20 at 10:35

2 Answers2

6

XPath 1.0:

<property name="Methodname" scope="default" type="STRING" 
          expression="concat(translate(substring(//name/text(), 1, 1), 
                                       'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
                                       'abcdefghijklmnopqrstuvwxyz'), 
                             substring(//name/text(), 2))"/>

XPath 2.0:

<property name="Methodname" scope="default" type="STRING" 
          expression="concat(lower-case(substring(//name/text(), 1, 1)), 
                             substring(//name/text(), 2))"/>
kjhughes
  • 106,133
  • 27
  • 181
  • 240
1

Just to add to kjhughes answer / this answer here, you'll probably want to use this in conjunction with the identity transform to copy the remainder of the document unscathed:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:template>

    <xsl:template match="@name[ancestor::property]">
        <xsl:attribute name="name">
            <xsl:value-of select="concat(translate(substring(., 1, 1), 
                           'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
                           'abcdefghijklmnopqrstuvwxyz'), substring(., 2))"/>
        </xsl:attribute>
    </xsl:template>

</xsl:stylesheet>
Community
  • 1
  • 1
StuartLC
  • 104,537
  • 17
  • 209
  • 285