英文:
ERR XTDE1425 while using Saxon - EE 11.4 On xml editor <Oxygen>
问题
我有以下XSLT代码。当我尝试转换我的XML文档时,收到以下错误消息:
“找不到名为Q{urn:js}RoundOff()的单参数函数”
我相信实际脚本没有问题,只是需要更改解析器设置的某些内容,但我不确定需要更改什么或在哪里更改这些设置。
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:js="urn:js"
exclude-result-prefixes="msxsl js">
<msxsl:script language="JavaScript" implements-prefix="js">
<![CDATA[
function roundOff(hours) {
return Math.round(hours * 100) / 100;
}
function getPeriodEndDate() {
var today = new Date();
var dayOfWeek = today.getDay();
var tdate = new Date(today.getFullYear(), today.getMonth(), today.getDate());
if (dayOfWeek === 0) {
tdate.setDate(tdate.getDate() - 1);
} else if (dayOfWeek === 1) {
tdate.setDate(tdate.getDate() - 2);
} else if (dayOfWeek === 2) {
tdate.setDate(tdate.getDate() - 3);
} else if (dayOfWeek === 3) {
tdate.setDate(tdate.getDate() - 4);
} else if (dayOfWeek === 4) {
tdate.setDate(tdate.getDate() - 5);
} else if (dayOfWeek === 5) {
tdate.setDate(tdate.getDate() - 6);
}
var year = tdate.getFullYear();
var month = tdate.getMonth() + 1;
var day = tdate.getDate();
if (month < 10) {
month = '0' + month;
}
if (day < 10) {
day = '0' + day;
}
return year + month + day;
}
]]>
</msxsl:script>```
....
<其他XSL代码行>
....
<xsl:value-of select="js:RoundOff(SickHoursAccrued + SickHoursUsed)" />
协助编辑或更改设置,使XSLT能够解析而无错误。
<details>
<summary>英文:</summary>
I have the following lines of XSLT. When i try to transform my xml doc I receive the following:
`Cannot find a 1-argument function named Q{urn:js}RoundOff()`
I believe that there is no issue with the actual script just something that I need to change in the parser setting but I am not sure what to or where to change these settings.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:js="urn:js"
exclude-result-prefixes="msxsl js">
<msxsl:script language="JavaScript" implements-prefix="js">
<![CDATA[
function roundOff(hours) {
return Math.round(hours * 100) / 100;
}
function getPeriodEndDate() {
var today = new Date();
var dayOfWeek = today.getDay();
var tdate = new Date(today.getFullYear(), today.getMonth(), today.getDate());
if (dayOfWeek === 0) {
tdate.setDate(tdate.getDate() - 1);
} else if (dayOfWeek === 1) {
tdate.setDate(tdate.getDate() - 2);
} else if (dayOfWeek === 2) {
tdate.setDate(tdate.getDate() - 3);
} else if (dayOfWeek === 3) {
tdate.setDate(tdate.getDate() - 4);
} else if (dayOfWeek === 4) {
tdate.setDate(tdate.getDate() - 5);
} else if (dayOfWeek === 5) {
tdate.setDate(tdate.getDate() - 6);
}
var year = tdate.getFullYear();
var month = tdate.getMonth() + 1;
var day = tdate.getDate();
if (month < 10) {
month = '0' + month;
}
if (day < 10) {
day = '0' + day;
}
return year + month + day;
}
]]>
</msxsl:script>```
....
<Additional lines of xsl>
....
<xsl:value-of select="js:RoundOff(SickHoursAccrued + SickHoursUsed)" />
Assistance in editing or changing settings to allow the xslt to parse without errors
答案1
得分: 1
基本上,你似乎期望能够使用J(ava)Script为XSLT实现扩展函数,这并不是Saxon支持的功能。
XSLT 2和3以及Saxon 11是XSLT 3处理器,具有丰富的XPath函数库,与XPath和XQuery共享,并且允许你在纯粹的XSLT/XPath中声明和实现自己的函数。
因此,首先检查你需要的功能是否在 https://www.w3.org/TR/xpath-functions-31/ 中可用(例如 https://www.w3.org/TR/xpath-functions-31/#func-round),如果不可用,请在XSLT/XPath中使用 xsl:function
进行实现:https://www.w3.org/TR/xslt-30/#stylesheet-functions
英文:
Basically, you seem to expect to be able to implement extension functions for XSLT with J(ava)Script, that is not something that Saxon supports.
XSLT 2 and 3, and Saxon 11 is an XSLT 3 processor, have a rich XPath function library shared with XPath and XQuery, and furthermore allow you to declare and implement your own functions in pure XSLT/XPath.
So first check whether any of the functionality you need is available in https://www.w3.org/TR/xpath-functions-31/ (e.g. https://www.w3.org/TR/xpath-functions-31/#func-round), if not, implement it in XSLT/XPath using xsl:function
: https://www.w3.org/TR/xslt-30/#stylesheet-functions
答案2
得分: 0
你可以尝试在Oxygen中编辑你使用的转换场景,并在Transformer组合框中选择一个可用的MSXML处理器,而不是Saxon 11吗?
https://www.oxygenxml.com/doc/ug-editor/topics/supported-XSLT-processors-x-2.html
英文:
How about if you edit the transformation scenario you use in Oxygen and in the Transformer combo box you select one of the available MSXML processors instead of Saxon 11?
https://www.oxygenxml.com/doc/ug-editor/topics/supported-XSLT-processors-x-2.html
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论