Biztalk XSLT1.0 使用变量值
Biztalk XSLT1.0 using variable value
我有一个 xslt1.0,其中编写了一个 functoid 脚本来获取当前日期时间,这将在运行时存储到一个名为 var:v1.
的变量中
<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var s0 userCSharp" version="1.0" xmlns:s0="http://MuleSoft.Bazaarvoice.FlatFileSchema1" xmlns:ns0="http://www.bazaarvoice.com/xs/PRR/ProductFeed/14.7" xmlns:userCSharp="http://schemas.microsoft.com/BizTalk/2003/userCSharp">
<xsl:output method="xml" version="1.0" indent="yes"/>
<xsl:key name="groupbycategory" match="Root_Child1" use="CategoryExternalId"/>
<xsl:template match="/">
<xsl:apply-templates select="/s0:Root"/>
</xsl:template>
<xsl:variable name="var:v1" select="userCSharp:CurrentDateTime()" />
<xsl:template match="/s0:Root">
<Feed name="WhiteStuff" extractDate="2021-08-25T16:51:53" incremental="false" xmlns="http://www.bazaarvoice.com/xs/PRR/ProductFeed/14.7">
.
.
.
</Feed>
</xsl:template>
<msxsl:script language="C#" implements-prefix="userCSharp"><![CDATA[
public static string CurrentDateTime()
{
return DateTime.Now.ToString("s");
}
]]></msxsl:script>
</xsl:stylesheet>
我的最后一个任务是用该变量替换硬编码的“2021-08-25T16:51:53”,这样我的输出将继续如下所示:
<?xml version="1.0" encoding="utf-8"?>
<Feed name="WhiteStuff" extractDate="2021-08-25T16:51:53" incremental="false" xmlns="http://www.bazaarvoice.com/xs/PRR/ProductFeed/14.7" xmlns:ns0="http://www.bazaarvoice.com/xs/PRR/ProductFeed/14.7">
显然 extractDate 会根据运行时而变化。
使用属性值模板 extractDate="{$var:v1}"
而不是文字值似乎是明显的 XSLT 方式,无论是使用 XSLT 1 还是其他方法或将值绑定到变量的 functoid。
我有一个 xslt1.0,其中编写了一个 functoid 脚本来获取当前日期时间,这将在运行时存储到一个名为 var:v1.
的变量中<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var s0 userCSharp" version="1.0" xmlns:s0="http://MuleSoft.Bazaarvoice.FlatFileSchema1" xmlns:ns0="http://www.bazaarvoice.com/xs/PRR/ProductFeed/14.7" xmlns:userCSharp="http://schemas.microsoft.com/BizTalk/2003/userCSharp">
<xsl:output method="xml" version="1.0" indent="yes"/>
<xsl:key name="groupbycategory" match="Root_Child1" use="CategoryExternalId"/>
<xsl:template match="/">
<xsl:apply-templates select="/s0:Root"/>
</xsl:template>
<xsl:variable name="var:v1" select="userCSharp:CurrentDateTime()" />
<xsl:template match="/s0:Root">
<Feed name="WhiteStuff" extractDate="2021-08-25T16:51:53" incremental="false" xmlns="http://www.bazaarvoice.com/xs/PRR/ProductFeed/14.7">
.
.
.
</Feed>
</xsl:template>
<msxsl:script language="C#" implements-prefix="userCSharp"><![CDATA[
public static string CurrentDateTime()
{
return DateTime.Now.ToString("s");
}
]]></msxsl:script>
</xsl:stylesheet>
我的最后一个任务是用该变量替换硬编码的“2021-08-25T16:51:53”,这样我的输出将继续如下所示:
<?xml version="1.0" encoding="utf-8"?>
<Feed name="WhiteStuff" extractDate="2021-08-25T16:51:53" incremental="false" xmlns="http://www.bazaarvoice.com/xs/PRR/ProductFeed/14.7" xmlns:ns0="http://www.bazaarvoice.com/xs/PRR/ProductFeed/14.7">
显然 extractDate 会根据运行时而变化。
使用属性值模板 extractDate="{$var:v1}"
而不是文字值似乎是明显的 XSLT 方式,无论是使用 XSLT 1 还是其他方法或将值绑定到变量的 functoid。