1

I collect string to xpath

<property xmlns:t="https://services" name="xPathElemet" expression="fn:concat(//t:SNILS/, $func:element)"/>

and I want to run this xpath and write the value of a Property

<property name="KEY" expression="get-property('xPathElemet')"/>

but receive only collected a string

how to xpath of the Property?

example code sequence :

<iterate continueParent="true" expression="//t:Employee">
    <target>
        <sequence>
            <call-template target="save_element">
                <with-param name="key_element" value="Name"/>
            </call-template>
        </sequence>
    </target>
</iterate>

example code template :

<template xmlns="http://ws.apache.org/ns/synapse" name="save_element">
    <parameter name="key_element"/>  <!--example: "Name"-->
    <sequence>
        <property name="KEY" expression="fn:concat(//t:Employee/t:SNILS, ':' ,$func:key_element)" scope="default"
                  type="STRING"/>             <!--example: "111-111-111-1:Name"-->
        <property name="xPathElemet" expression="fn:concat('//t:Employee/t:', $func:element)"/>      <!--example: "//t:Employee/t:Name"-->
        <property name="VALUE" expression="get-property('xPathElemet')" scope="default" type="STRING"/>      <!--example: Den (Now it does not work)-->
        <dbreport>
            <connection>
                <pool>
                    <seetings/>
                </pool>
            </connection>
            <statement>
                <sql>
                    <![CDATA[insert into cache( key , value ) values (?, ?);]]></sql>      <!--insert new line where key = "111-111-111-1:Name" and value = "Den"-->
                <parameter expression="get-property('KEY')" type="VARCHAR"/>
                <parameter expression="get-property('VALUE')" type="VARCHAR"/>
            </statement>
        </dbreport>
    </sequence>
</template>

example xml:

<Employees xmlns="https://services">
    <Employee>
        <SNILS>111-111-111-1</SNILS>
        <Name>Den</Name>
    </Employee>
    <Employee>
        <SNILS>111-111-111-2</SNILS>
        <Name>Elena</Name>
    </Employee>
</Employees>
Community
  • 1
  • 1
Gleb Belyaev
  • 1,009
  • 1
  • 14
  • 23

2 Answers2

3

Use evaluate

In your case:

<property xmlns:t="https://services" name="xPathElemet" expression="fn:concat(//t:SNILS/, $func:element)"/>
<property name="KEY" expression="evaluate(get-property('xPathElemet'))"/>

You can find more infomation in this blog.

tyfyh
  • 333
  • 2
  • 15
0

Please try the following and see if it works

<property xmlns:t="https://services" name="xPathElemet" expression="fn:concat(//t:SNILS/, $func:element)"/>
<property xmlns:t="https://services" name="xPathfull" expression="fn:concat(get-property('xPathElemet'),'/text()')"/>
<property name="KEY" expression="get-property('xPathfull')"/>

What was missing from your code was the /text() which refer to the parameters of the given xpath. Please try this

Nadeesha
  • 825
  • 2
  • 9
  • 12
  • I first need to build string for Xpath, and then execute it. how does this help me? – Gleb Belyaev Jul 12 '13 at 08:06
  • so what you want is to have the corresponding value to appear than just the xpath? – Nadeesha Jul 12 '13 at 08:39
  • I do not have ready in advance xPpath, I give value to the template, and there build xPpath, and I need to get the value of – Gleb Belyaev Jul 12 '13 at 08:59
  • I have modified the answer please check whether it works, you may have to change the code a bit based on the values returned, but the baseline is to include /text() after whatever the xpath text – Nadeesha Jul 12 '13 at 09:07
  • what you need to be doing is concatinate the following //t:SNILS/, $func:element and '/text()' so your final xpath would look like something like this '//m0:getQuote/m0:request/m0:Id/text()' – Nadeesha Jul 12 '13 at 10:20
  • how execute it? how to get value for Xpath? – Gleb Belyaev Jul 12 '13 at 10:30
  • How to get the values to the XPath would depend on the logic that u are executing. I would suggest you to manually enter the XPath 1st and see if you can get the values correctly and then try to get them dynamically. – Nadeesha Jul 12 '13 at 10:54
  • The expression is tested, it is correct. Now I need to make a dynamic and get the value. how to get value for dynamic xpath? value will be stored in the db – Gleb Belyaev Jul 12 '13 at 10:59
  • Can you please give a more detailed code I am unable to understand your scenario – Nadeesha Jul 13 '13 at 04:24