I find we can dynamically create XPath expressions and use them for the XPath command <xpath expression="${my_xpath}">... I have not been able to generate a dynamic query in XQuery. Example:
<var-def name="my_xpath">//td[3]/h2[1]</var-def> <xquery> <xq-param name="item"><var name="item"/></xq-param> <xq-param name="my_xpath"><var name="my_xpath"/></xq-param> <xq-expression><![CDATA let $name := data($item{$my_xpath}) return <product> <name>{normalize-space($name)}</name> </product> ]></xq-expression> </xquery>
This code produces an exception. Is there a way to make this work?
try to surround xquery expression with <template>:
<xq-expression> <template> <![CDATA let $name := data($item${my_xpath}) return <product> <name>{normalize-space($name)}</name> </product> ]> </template> </xq-expression>
so that templating processor will first replace your xpath with variable.
makes perfect sense. thanks a million
Log in to post a comment.
I find we can dynamically create XPath expressions and use them for the XPath command <xpath expression="${my_xpath}">...
I have not been able to generate a dynamic query in XQuery. Example:
<var-def name="my_xpath">//td[3]/h2[1]</var-def>
<xquery>
<xq-param name="item"><var name="item"/></xq-param>
<xq-param name="my_xpath"><var name="my_xpath"/></xq-param>
<xq-expression><![CDATA
let $name := data($item{$my_xpath})
return
<product>
<name>{normalize-space($name)}</name>
</product>
]></xq-expression>
</xquery>
This code produces an exception. Is there a way to make this work?
try to surround xquery expression with <template>:
<xq-expression>
<template>
<![CDATA
let $name := data($item${my_xpath}) return
<product>
<name>{normalize-space($name)}</name>
</product>
]>
</template>
</xq-expression>
so that templating processor will first replace your xpath with variable.
makes perfect sense. thanks a million