Using xpath functions

Hello:

I want to use the xpath “replace()” function, but Mediator doestn’t recognize it:

something like:


{replace('hello','h','H')} 

in a property set doesn’t work. I’ve tried with namespaces:


<set xmlns:fn="http://www.w3.org/2005/02/xpath-functions" 
property="hi" value="{fn:replace('hello','h','H')}" xbd.zid="N400063"/>

…with the same result. I’m using 7.4.1.1 version.

Any idea? Thanks in advance.

Hi,

The replace function for XPath is part of the XPath 2.0 Candidate Recommendation submited to the W3C on 03.11.2005. Most implimentations of this XPath version and the replace function in general are based on the W3C XPath 2.0 Draft Requirement from 22.08.2003.
Because of this, you will find very few “production” quality Xpath evaluation engines already implimenting the XPath 2.0. Xalan is currently the industry standard for this and their most recent release, Xalan 2.7, still bases its XPath functionality on XPath 1.0.
If this is a functionality you cannot do without, I suggest you use one of the XPath 2.0 reference libraries and build a custom component to perform the transformation indicated.

Thanks 4 replying.

It’s very frustrating that Mediator hasn’t this funcionality. I hope that in future releases, Xpath 2.0 will be implemented. I’ll follow your suggestion: develop an external component.

Hello again:

This is the way I’ve implemented the replace function:



<?xml version="1.0" encoding="UTF-8"?>
<sequence version="4.0" xbd.zid="N400001">
    <block xbd.zid="N400002">
        <!--{Name: JavaObjectGateway};{Notes: }-->
        <step component="SagJavaObjectGateway" xbd.object.class="java.lang.String" xbd.object.function="Create" xbd.object.methodDescriptor="(Ljava/lang/String;)V" xbd.object.parm0="{'$with_blankspaces'}" xbd.object.result="MyString" xbd.zid="N400003"/>
        <!--{Name: JavaObjectGateway};{Notes: }-->
        <step component="SagJavaObjectGateway" xbd.object.function="Call" xbd.object.method="replaceAll" xbd.object.methodDescriptor="Ljava/lang/String;Ljava/lang/String;" xbd.object.object="MyString" xbd.object.parm0=" " xbd.object.parm1="_" xbd.object.property="without_blankspaces" xbd.zid="N400004"/>
    </block>
</sequence>

The only problem I have with this solution is that when I open the sequence in graphical mode, Mediator removes the blankspace value " " and puts an empty string.

Is there any way for defining a blankspace value in a mediator property?

Hello again:

This is the way I’ve implemented the replace function:



<?xml version="1.0" encoding="UTF-8"?>
<sequence version="4.0" xbd.zid="N400001">
    <block xbd.zid="N400002">
        <!--{Name: JavaObjectGateway};{Notes: }-->
        <step component="SagJavaObjectGateway" xbd.object.class="java.lang.String" xbd.object.function="Create" xbd.object.methodDescriptor="(Ljava/lang/String;)V" xbd.object.parm0="{'$with_blankspaces'}" xbd.object.result="MyString" xbd.zid="N400003"/>
        <!--{Name: JavaObjectGateway};{Notes: }-->
        <step component="SagJavaObjectGateway" xbd.object.function="Call" xbd.object.method="replaceAll" xbd.object.methodDescriptor="Ljava/lang/String;Ljava/lang/String;" xbd.object.object="MyString" xbd.object.parm0=" " xbd.object.parm1="_" xbd.object.property="without_blankspaces" xbd.zid="N400004"/>
    </block>
</sequence>

The only problem I have with this solution is that when I open the sequence in graphical mode, Mediator removes the blankspace value " " and puts an empty string.

Is there any way for defining a blankspace value in a mediator property?

This sounds like a bug in the studio. It shouldn’t be altering your property values at all. If you can, please report this via ServLine24.

Thanks,

Hi All,

If you are only doing single character replacements, you can use the XPath “translate” function. The arguments are much longer, but it is part of the XPath 1.0 specification.

Hope this helps.