Ниже находится входное сообщение:
Ввод:
Record Name : Member
Fields: Company Name , Person Name , State , Country , Amount , CombinedState
Это мой ввод XML:
<ns0:Root xmlns:ns0="Test">
<Detail>
<Member>
<CompanyName>XYZ</CompanyName>
<PersonName>Ashwin</PersonName>
<State>KS</State>
<Country>USA</Country>
<Amount>1000</Amount>
<CombinedState>Yes</CombinedState>
</Member>
<Member>
<CompanyName>XYZ</CompanyName>
<PersonName>Lingam</PersonName>
<State>AZ</State>
<Country>USA</Country>
<Amount>1001</Amount>
<CombinedState>Yes</CombinedState>
</Member>
<Member>
<CompanyName>XYZ</CompanyName>
<PersonName>John</PersonName>
<State>KS</State>
<Country>USA</Country>
<Amount>1000</Amount>
<CombinedState>Yes</CombinedState>
</Member>
<Member>
<CompanyName>ABC</CompanyName>
<PersonName>Larry</PersonName>
<State>IL</State>
<Country>USA</Country>
<Amount>1000</Amount>
<CombinedState>No</CombinedState>
</Member>
<Member>
<CompanyName>ABC</CompanyName>
<PersonName>Lingam</PersonName>
<State>NJ</State>
<Country>USA</Country>
<Amount>1001</Amount>
<CombinedState>Yes</CombinedState>
</Member>
<Member>
<CompanyName>Bright</CompanyName>
<PersonName>John</PersonName>
<State>FL</State>
<Country>USA</Country>
<Amount>1000</Amount>
<CombinedState>Yes</CombinedState>
</Member>
</Detail>
</ns0:Root>
Вывод должен выглядеть следующим образом:
<ns0:Root xmlns:ns0="http://BizTalk_Server_Project1.Output">
<T>
<SeqNo>1</SeqNo>
<Name>Something</Name>
</T>
<Group>
<A>
<CompanyName>XYZ</CompanyName>
<Segment>A</Segment>
</A>
<B>
<CompanyName>XYZ</CompanyName>
<PersonName>Ashwin</PersonName>
<Country>USA</Country>
<State>KS</State>
<Amount>1000</Amount>
</B>
<B>
<CompanyName>XYZ</CompanyName>
<PersonName>Lingam</PersonName>
<Country>USA</Country>
<State>AZ</State>
<Amount>1001</Amount>
</B>
<B>
<CompanyName>XYZ</CompanyName>
<PersonName>John</PersonName>
<Country>USA</Country>
<State>KS</State>
<Amount>1000</Amount>
</B>
<C>
<TotalAmount>3001</TotalAmount>
</C>
<K>
<State>KS</State>
<TotAmount>2000</TotAmount>
</K>
<K>
<State>AZ</State>
<TotAmount>1001</TotAmount>
</K>
</Group>
<Group>
<A>
<CompanyName>ABC</CompanyName>
<Segment>A</Segment>
</A>
<B>
<CompanyName>ABC</CompanyName>
<PersonName>Larry</PersonName>
<Country>USA</Country>
<State>IL</State>
<Amount>1000</Amount>
</B>
<B>
<CompanyName>ABC</CompanyName>
<PersonName>Lingam</PersonName>
<Country>USA</Country>
<State>NJ</State>
<Amount>1001</Amount>
</B>
<C>
<TotalAmount>2001</TotalAmount>
</C>
<K>
<State>NJ</State>
<TotAmount>1001</TotAmount>
</K>
</Group>
<Group>
<A>
<CompanyName>Bright</CompanyName>
<Segment>A</Segment>
</A>
<B>
<CompanyName>Bright</CompanyName>
<PersonName>John</PersonName>
<Country>USA</Country>
<State>AZ</State>
<Amount>1000</Amount>
</B>
<C>
<TotalAmount>1000</TotalAmount>
</C>
<K>
<State>AZ</State>
<TotAmount>1000</TotAmount>
</K>
</Group>
</ns0:Root>
XSLT, который я пробовал:
<?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="Test" xmlns:ns0="http://BizTalk_Server_Project1.Output" xmlns:userCSharp="http://schemas.microsoft.com/BizTalk/2003/userCSharp">
<xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />
<xsl:key name="group1" match ="Member" use ="CompanyName"/>
<xsl:key name="group2" match ="Member" use ="concat(CompanyName,'|',PersonName)"/>
<xsl:key name="group3" match ="Member" use ="concat(CompanyName,'|',State)"/>
<xsl:template match="/">
<xsl:apply-templates select="/s0:Root" />
</xsl:template>
<xsl:template match="/s0:Root">
<xsl:variable name="var:v1" select="userCSharp:StringConcat("1")" />
<xsl:variable name="var:v2" select="userCSharp:StringConcat("1234567")" />
<ns0:Root>
<T>
<SeqNo>
<xsl:value-of select="$var:v1" />
</SeqNo>
<Name>
<xsl:value-of select="$var:v2" />
</Name>
</T>
<xsl:for-each select="Detail/Member[generate-id(.)=generate-id(key('group1',CompanyName))]">
<Group>
<A>
<CompanyName>
<xsl:value-of select="CompanyName/text()" />
</CompanyName>
<Segment>
<xsl:value-of select="'A'" />
</Segment>
</A>
<xsl:for-each select="Detail/Member[generate-id(.)=generate-id(key('group2',concat(CompanyName,'|',PersonName)))]"> <!--2nd key-->
<B>
<CompanyName>
<xsl:value-of select="CompanyName/text()" />
</CompanyName>
<PersonName>
<xsl:value-of select="PersonName/text()" />
</PersonName>
<Country>
<xsl:value-of select="Country/text()" />
</Country>
<State>
<xsl:value-of select="State/text()" />
</State>
<Amount>
<xsl:value-of select="Amount/text()" />
</Amount>
</B>
</xsl:for-each>
<c> <!--Uses 1st key-->
<TotalAmount>
<xsl:value-of select="sum(key('group1', CompanyName)/Amount)" />
</TotalAmount>
</c>
<xsl:for-each select="Detail/Member[generate-id(.)=generate-id(key('group3',concat(CompanyName,'|',State)))]"> <!--3rd Key-->
<k>
<State>
<xsl:value-of select="State/text()" />
</State>
<TotAmount>
<xsl:value-of select="sum(key('group3', concat(CompanyName,'|',State))/Amount)" />
</TotAmount>
</k>
</xsl:for-each>
</Group>
</xsl:for-each>
</ns0:Root>
</xsl:template>
<msxsl:script language="C#" implements-prefix="userCSharp"><![CDATA[
public string StringConcat(string param0)
{
return param0;
}
]]></msxsl:script>
</xsl:stylesheet>
Требование:
Структура желаемого выхода следующая:
Record Name : T
Field Name :SeqNo , Value :1 ( HardCoded )
Field Name : Name , Value : Something(Hardcoded)
Record Name:
Group:
Child Record Name: A (This Child Record has max occurs 1 and Occurs only 1 per Company Name)
Req: For each company A record will be created only once
Field Name: CompanyName , Value: From the input field Company Name
Field Name: Segment , Value: A (HardCoded)
Child Record Name : B ( This Child record Max occurs unbounded and groups all member under Each company Name )
Example and requirement : Input Member have company name “xyz” and total number of member having company name xyz is “3” so the B record will occur 3 times
Field Name: Company Name , Value: From the input field Company Name
Field Name: Person Name , Value : From the input field Person Name
Field Name: Country , Value : From the input field Country
Field Name: State , value : From the input field State
Field Name : Amount , Value : from the input field Amount
Child Record Name : C (This Child Record has max occurs 1 )
Field Name : Total Amount , Value : This will be the cumulative of the amounts under each company
Example : If Company name XYZ have 3 member each of 1000 then the cumulative will be 3000
Child Record Name : K(This child Record has max occurs unbounded )
Field Name : State , Value : From the input field State
Field Name : TotAmount , Value : Below is the requirement
Требование:
Поле «CombinedState» во входных данных скажет, является ли «Да» или «Нет», если его «Да», то оно создает одну запись для каждого состояния и суммирует сумму для каждого состояния.
Пример:
Для компании XYZЕсть 3 члена, и их состояния - KS, AZ и KS, поэтому мы должны создать две записи K, т.е. одну для KS и одну для AZ, и нам нужно сложить сумму для KS, поскольку XYZ имеет 2 члена в состоянии KS,
Проблема:
Каждая запись внутри группы использует разные ключи, написанное мной XSLT не работает для записей B и K.