Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在xpath中使用头来设置路由中的另一个头?_Xpath_Apache Camel - Fatal编程技术网

在xpath中使用头来设置路由中的另一个头?

在xpath中使用头来设置路由中的另一个头?,xpath,apache-camel,Xpath,Apache Camel,我已在路由中定义了一个标头,并希望使用标头的值来确定另一个标头值 例如: <route id="use_reference_number"> <from uri="direct:file_name:use_reference_number"> <setHeader headerName="FirstNameOfStudent"> <xpath resultType="java.lang.String">//*/Student/Stud

我已在路由中定义了一个标头,并希望使用标头的值来确定另一个标头值

例如:

<route id="use_reference_number">
 <from uri="direct:file_name:use_reference_number">
  <setHeader headerName="FirstNameOfStudent">
    <xpath resultType="java.lang.String">//*/Student/StudentName/FirstName/text()</xpath>
  </setHeader>

  <setHeader headerName="NumberOfStudentByThatName">
    <xpath>count(//*/Student[StudentName/FirstName/text() = ${in.header.FirstNameOfStudent}])</xpath>
  </setHeader>
</route>

//*/学生/StudentName/FirstName/text()
计数(//*/Student[StudentName/FirstName/text()=${in.header.FirstNameOfStudent}])
基本上,在这里,根据分离x路径的结果,我想确定第二个路径中的students标记的数量,最后在选择中使用“NumberOfStudentByThatName”——何时采取单独的路径。但是当我使用这个表达式时,它返回0。我认为它无法解决标题问题

<setHeader headerName="NumberOfStudentByThatName">
   <xpath>count(//*/Student[StudentName/FirstName/text() = 'AMAN'])</xpath>
</setHeader>

计数(//*/Student[StudentName/FirstName/text()='AMAN'])
当我像上面那样使用它时,它工作得非常好,但是我不想硬编码任何值,而是使用输入中的内容

在本例中,我有两个单独的XML,希望以更简洁的方式使用它们。

根据需要,有一些特殊的Camel XPath函数,如:body、
In:header
等: 我想你可以这样做:

<setHeader headerName="NumberOfStudentByThatName">
  <xpath>count(//*/Student[StudentName/FirstName/text() = in:header("FirstNameOfStudent")])</xpath>
</setHeader>

计数(//*/Student[StudentName/FirstName/text()=in:header(“学生的名字”))
另外,我没有测试它,我也不确定标题名中是否有双引号-文档页面会显示URL编码的值,如
';学生的名字'。所以,你可以找到答案