C# 重复记录BizTalk映射上的内联XSLT 1.0计数

C# 重复记录BizTalk映射上的内联XSLT 1.0计数,c#,xslt-1.0,biztalk,biztalk-mapper,biztalk-2016,C#,Xslt 1.0,Biztalk,Biztalk Mapper,Biztalk 2016,我在BizTalk项目中编写内联XSLT 1.0时遇到问题,我正在尝试获取字段状态的计数(如果它等于INactive),下面是我尝试的输入xml、预期xml和XSLT 输入XML: <ns0:Root xmlns:ns0="http://Test"> <ns0:Source>EXT</ns0:Source> <ns0:Lines> <ns0:Code>A</ns0:Code>

我在BizTalk项目中编写内联XSLT 1.0时遇到问题,我正在尝试获取字段状态的计数(如果它等于INactive),下面是我尝试的输入xml、预期xml和XSLT

输入XML:

<ns0:Root xmlns:ns0="http://Test">
    <ns0:Source>EXT</ns0:Source>
    <ns0:Lines>
        <ns0:Code>A</ns0:Code>
        <ns0:Status>Active</ns0:Status>
    </ns0:Lines>
    <ns0:Lines>
        <ns0:Code>A</ns0:Code>
        <ns0:Status>Active</ns0:Status>
    </ns0:Lines>
    <ns0:Lines>
        <ns0:Code>A</ns0:Code>
        <ns0:Status>InActive</ns0:Status>
    </ns0:Lines>
    <ns0:Lines>
        <ns0:Code>A</ns0:Code>
        <ns0:Status>InActive</ns0:Status>
    </ns0:Lines>
        <ns0:Lines>
        <ns0:Code>A</ns0:Code>
        <ns0:Status>InActive</ns0:Status>
    </ns0:Lines>
</ns0:Root>
预期产出:

<ns0:Root xmlns:ns0="http://TestOutPut">
  <Count>3</Count>
</ns0:Root>
内联XSLT脚本Functoid:

<xsl:element name="Count"><xsl:value-of select = "count(Lines[Status='Inactive'])" /></xsl:element>
条件:如果状态为“非活动”,则获取状态计数的编号


帮帮我,不知道我哪里做错了,因为需要将目标命名空间更改为http://TestOutPut,然后使用变量存储来自上一个命名空间的值http://Test

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://Test">
    <xsl:template match="ns0:Root">
        <xsl:variable name="count" select="count(ns0:Lines[ns0:Status='InActive'])" />
        <ns0:Root xmlns:ns0="http://TestOutPut">
            <Count><xsl:copy-of select="$count" /></Count>
        </ns0:Root>
    </xsl:template> 
</xsl:stylesheet>

根据需要将目标命名空间更改为http://TestOutPut,然后使用变量存储来自上一个命名空间的值http://Test

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://Test">
    <xsl:template match="ns0:Root">
        <xsl:variable name="count" select="count(ns0:Lines[ns0:Status='InActive'])" />
        <ns0:Root xmlns:ns0="http://TestOutPut">
            <Count><xsl:copy-of select="$count" /></Count>
        </ns0:Root>
    </xsl:template> 
</xsl:stylesheet>

对于使用脚本函数的内联XSLT,您需要具备以下条件,其中需要包括本地名称以及在条件中使用文本函数

<xsl:variable name="count" select="count(/*[local-name()='Root' and namespace-uri()='http://Test']/*[local-name()='Lines' and namespace-uri()='http://Test']/*[local-name()='Status' and namespace-uri()='http://Test'][text()='InActive'])" />

<Count><xsl:copy-of select="$count" /></Count>
通过单击映射中的节点并从属性窗口复制实例XPath,可以获得正确的XSLT路径

如果没有多个名称空间导致问题,可以删除名称空间uri以简化它

<xsl:variable name="count" select="count(/*[local-name()='Root']/*[local-name()='Lines']/*[local-name()='Status'][text()='InActive'])" />

<Count><xsl:copy-of select="$count" /></Count>

注意:XSLT区分大小写,因此非活动和非活动不相等。

对于使用脚本函数的内联XSLT,您需要具备以下条件,其中需要包括本地名称以及在条件中使用文本函数

<xsl:variable name="count" select="count(/*[local-name()='Root' and namespace-uri()='http://Test']/*[local-name()='Lines' and namespace-uri()='http://Test']/*[local-name()='Status' and namespace-uri()='http://Test'][text()='InActive'])" />

<Count><xsl:copy-of select="$count" /></Count>
通过单击映射中的节点并从属性窗口复制实例XPath,可以获得正确的XSLT路径

如果没有多个名称空间导致问题,可以删除名称空间uri以简化它

<xsl:variable name="count" select="count(/*[local-name()='Root']/*[local-name()='Lines']/*[local-name()='Status'][text()='InActive'])" />

<Count><xsl:copy-of select="$count" /></Count>

注意:XSLT区分大小写,因此不活动和不活动不相等。

Yes:countns0:Lines[ns0:Status='Inactive']。您可以从xsl:for-each开始,然后去掉它。@michael.hor257k xsl:stylesheet'不能是'xsl:stylesheet'元素的子元素。-这是我使用脚本在内联xslt中收到的错误functoid@sukra为什么你的评论是针对我的?我对BizTalk、内联XSLT或脚本functoids一无所知—这就是为什么我没有回答您的问题。如果您使用映射中xsl文件的自定义XSLT路径,则上述答案是正确的。对于内联XSLT,请参见我的答案。Yes:countns0:Lines[ns0:Status='InActive']。您可以从xsl:For-each开始并去掉它。@michael.hor257k xsl:stylesheet'不能是'xsl:stylesheet'元素的子元素。-这是我使用脚本在内联XSLT中收到的错误functoid@sukra为什么你的评论是针对我的?我对BizTalk、内联XSLT或脚本functoids一无所知—这就是为什么我没有回答您的问题。如果您使用映射中xsl文件的自定义XSLT路径,则上述答案是正确的。有关内联XSLT,请参见我的答案。