1

I have a problem in writing a Inline XSLT 1.0 in my BizTalk Project , I am trying to get the count for a field Status if its equal to INactive , below is the Input xml , Expected xml and XSLT what i tried

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

Expected OutPut :

<ns0:Root xmlns:ns0="http://TestOutPut">
  <Count>3</Count>
</ns0:Root>

Inline XSLT ( Script Functoid ) :

<xsl:element name="Count"><xsl:value-of select = "count(Lines[Status='Inactive'])" /></xsl:element>

Condition : Get the No of Status (Count ) if Status = 'Inactive'

Help me out , don't know where i am doing it wrong

sukra
  • 123
  • 1
  • 10

2 Answers2

2

For inline XSLT using the Scripting Functiod you need to have the following where you need to include the local-name as well as using the text() function in the condition.

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

You can get the correct XSLT path by clicking on the node in the map and copying the Instance XPath from the Properties window.

You can remove the namespace-uri to simplify it if there aren't multiple namespaces to cause issues.

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

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

Note: XSLT is case sensitive, so Inactive and InActive are not equal.

Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54
1

As it required to change the target namespace to "http://TestOutPut", then use a variable to store the value from previous namespace "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>
Miller Cy Chan
  • 897
  • 9
  • 19