内联 XSLT 1.0 计数重复记录 BizTalk 映射

Inline XSLT 1.0 Count on Repeating Record BizTalk Map

我在我的 BizTalk 项目中编写内联 XSLT 1.0 时遇到问题,我正在尝试获取字段 Status 的计数,如果它等于 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>

条件:如果状态 = 'Inactive'

,则获取状态数(计数)

帮帮我,不知道我哪里做错了

由于需要将目标命名空间更改为“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>

对于使用 Scripting Functiod 的内联 XSLT,您需要在需要包含本地名称以及在条件中使用 text() 函数的地方具有以下内容。

<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>

您可以通过单击图中的节点并从属性 window 复制实例 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 区分大小写,因此 Inactive 和 InActive 不相等。