[英]Marklogic tde templates how to use string-join for numeric values
Is it possible to use string-join for numeric values in marklogic template?是否可以对 marklogic 模板中的数值使用字符串连接?
let json = xdmp.toJSON({
"instance": {
"uri": "/A/Uri/of/some/type.json",
"types": [
"1",
"2",
"3"
]
}
});
let tpl = xdmp.toJSON({
"template": {
"context": "/instance",
"enabled": true,
"rows": [
{
"schemaName": "namespace",
"viewName": "uri2types",
"columns": [
{
"name": "uri",
"scalarType": "anyURI",
"val": "./uri",
"nullable": true,
"invalidValues": "ignore"
}
,
{
"name": "type",
"scalarType": "string",
"val": "fn:string-join(./types, ', ')"
}
]
}
]
}
});
tde.validate([tpl]);
tde.nodeDataExtract([json], [tpl]);
And this code above works correct for string values but when I change types to array of numeric values I got error.上面的代码适用于字符串值,但是当我将类型更改为数值数组时出现错误。
"types": [
1,
2,
3
]
Is it possible to cast numbers to strings before join?是否可以在加入之前将数字转换为字符串?
Yes, you can adjust the XPath selecting the types
numbers, and turn them into strings using the fn:string()
function:是的,您可以调整选择
types
数字的 XPath,并使用fn:string()
函数将它们转换为字符串:
"val": "fn:string-join(./types/fn:string(.), ', ')"
Your example input has them as strings anyhow, but the above will work if they are strings or numbers in the JSON array.无论如何,您的示例输入将它们作为字符串,但如果它们是 JSON 数组中的字符串或数字,则上述方法将起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.