【发布时间】:2021-08-08 17:01:09
【问题描述】:
我正在将逻辑应用连接器“转换 XML”与具有 XSLT 映射版本 3.0 文件的集成帐户一起使用。
它正在转换我所需的 XML,但是当我包含 C# 代码来转换日期标记时抛出异常:
有没有人遇到过类似的问题,请告诉我。
我的 XSLT 文件内容
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:userCSharp="urn:my-scripts"
exclude-result-prefixes="msxsl"![97882-error.png][1]
>
<msxsl:script language="C#" implements-prefix="userCSharp">
<![CDATA[
public string FormatDateFunction(string inputDate)
{
string formatdate;
if(string.IsNullOrEmpty(inputDate))
return "";
formatdate = System.DateTime.Parse(inputDate).ToString("M/dd/yyyy");
return formatdate;
}
]]>
</msxsl:script>
<xsl:output method="xml" indent="yes"/>
<xsl:variable name="paramDate">
<xsl:value-of select="/*/XPathBody/Data" />
</xsl:variable>
<xsl:template match="/">
<MyHeader_1.0>
<MyTag>
<DueDate>
<xsl:value-of select="userCSharp:FormatDateFunction($paramDate)"/>
</DueDate>
<MyDate>
<xsl:choose>
<xsl:when test="$paramDate != ''">
<xsl:value-of select="userCSharp:FormatDateFunction($paramDate)"/>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</MyDate>
</MyTag>
</MyHeader_1.0>
</xsl:template>
</xsl:stylesheet>
逻辑应用出错
*
{
"Code": "InvalidXsltContent",
"Message": "An error occurred while transforming the given input with the provided map. Details: 'net.sf.saxon.trans.XPathException: Errors were reported during stylesheet compilation'.",
"Details": [
{
"Code": "InvalidXsltContent",
"Message": "{\"StatusCode\":400,\"ErrorCode\":7,\"Details\":null,\"Message\":\"An error occurred while transforming the given input with the provided map. Details: 'net.sf.saxon.trans.XPathException: Errors were reported during stylesheet compilation'.\",\"Data\":{},\"InnerException\":null,\"TargetSite\":{\"Name\":\"MoveNext\",\"AssemblyName\":\"Microsoft.Azure.Function.Common.Cloud, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\",\"ClassName\":\"Microsoft.Azure.Function.Xslt30Transform.BaseXslt30Transformer+<Transform>d__3\",\"Signature\":\"Void MoveNext()\",\"Signature2\":\"System.Void MoveNext()\",\"MemberType\":8,\"GenericArguments\":null},\"StackTrace\":\" at Microsoft.Azure.Function.Xslt30Transform.BaseXslt30Transformer.<Transform>d__3.MoveNext() in X:\\\\bt\\\\1186352\\\\repo\\\\src\\\\functions\\\\Scripts\\\\Function.Common.Cloud\\\\Xml\\\\BaseXslt30Transformer.cs:line 75\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()\\r\\n at Microsoft.Azure.Function.Xslt30Transform.Xslt30TransformRequestProcessor.<ProcessTransformRequest>d__2.MoveNext() in X:\\\\bt\\\\1186352\\\\repo\\\\src\\\\functions\\\\Scripts\\\\Function.Xslt30Transform\\\\Xslt30TransformRequestProcessor.cs:line 50\",\"HelpLink\":null,\"Source\":\"Microsoft.Azure.Function.Common.Cloud\",\"HResult\":-2146233088}",
"Details": null,
"InnerError": null
}
],
"InnerError": null
}
附加错误图片 enter image description here
任何帮助都会非常感激。
提前致谢。
【问题讨论】:
-
XSLT 3 支持 XPath 3.1 函数
format-date和format-dateTime所以我会尝试将它们用于日期格式。对日期解析也有一些有限的支持,但是“本机”XSLT/XPath 2 和更高版本的xs:date格式是YYYY-MM-DD。但通常很容易定义您的 XSLT 函数以从不同的日期格式转换为xs:date格式。 -
如果您使用 XSLT 映射
version="1.0"而不是version="3.0",嵌入式 C# 代码是否有效?我在您的 XSLT 中看不到任何使用 XSLT 3 功能的东西,因此,如果您想在 XSLT 中使用 C#,您可能可以使用 XSLT 1 来实现,我认为使用的是XslCompiledTransform而不是 Saxon。即使对于 XslCompiledTransform,您也可能需要允许在 XSLT 中使用嵌入式 C#。 -
@MartinHonnen 我已经尝试过使用 XSLT 2.0 和 3.0 的 format-date 函数,当我在 Visual Studio 中调试它时效果很好。唯一的问题是当我将相同的 XSLT 与 Azure 集成帐户 - 逻辑应用程序中的映射文件一起使用时,它会引发错误。
标签: xml xslt azure-logic-apps