How to do this kind of message transformation?
data this:
1,toys, 2010-01-01, 100.00
1,toys, 2010-01-02, 210.00
1,food, 2010-01-01, 500.00
2,toys, 2010-01-03, 220.00
try transform file format has structure:
<dataset>
<dimension value="1">
<metric category="toy">
<data date="2010-01-01" sales="100.00"/>
<data date="2010-01-02" sales="210.00"/>
</metric>
<metric category="food">
<data date="2010-01-01" sales="500.00"/>
</metric>
</dimension>
<dimension value="2">
<metric category="toy">
<data date="2010-01-03" sales="220.00"/>
</metric>
</dimension>
</dataset>
reckon easy mapping, didn't figure out functoid can use apply logic.
ideas?
thank you.
i did small poc , able mapping need. first created flatfile schema convert input text file xml , created custom xslt using muenchian method transform to the desired output.
xslt:
<
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" version="1.0">
<xsl:output omit-xml-declaration="yes" indent="yes" method="xml" version="1.0"/>
<xsl:key name="group" match="/*[local-name()='root' , namespace-uri()='http://testproject.ffsale']/*[local-name()='dataset' , namespace-uri()='']" use="concat(dimension, category)"/>
<xsl:template match="/">
<xsl:apply-templates select="/*[local-name()='root' , namespace-uri()='http://testproject.ffsale']"/>
</xsl:template>
<xsl:template match="/*[local-name()='root' , namespace-uri()='http://testproject.ffsale']">
<dataset>
<xsl:for-each select="/*[local-name()='root' , namespace-uri()='http://testproject.ffsale']/*[local-name()='dataset' , namespace-uri()=''][generate-id()=generate-id(key('group', concat(dimension, category))[1])]">
<dimension>
<xsl:attribute name="value"><xsl:value-of select="dimension"/></xsl:attribute>
<metric>
<xsl:attribute name="category"><xsl:value-of select="category"/></xsl:attribute>
<xsl:for-each select="key('group', concat(dimension, category))">
<data>
<xsl:attribute name="date"><xsl:value-of select="date"/></xsl:attribute>
<xsl:attribute name="sales"><xsl:value-of select="sales"/></xsl:attribute>
</data>
</xsl:for-each>
</metric>
</dimension>
</xsl:for-each>
</dataset>
</xsl:template> </
xsl:stylesheet>
testing: tested above xslt using following input message. please see results in output message.
input message:
<
root xmlns="http://testproject.ffsale">
<dataset xmlns="">
<dimension>1</dimension>
<category>toys</category>
<date> 2010-01-01</date>
<sales> 100.00</sales>
</dataset>
<dataset xmlns="">
<dimension>1</dimension>
<category>toys</category>
<date> 2010-01-02</date>
<sales> 210.00</sales>
</dataset>
<dataset xmlns="">
<dimension>1</dimension>
<category>food</category>
<date> 2010-01-01</date>
<sales> 500.00</sales>
</dataset>
<dataset xmlns="">
<dimension>2</dimension>
<category>toys</category>
<date> 2010-01-03</date>
<sales> 220.00</sales>
</dataset> </
root>
output message
<
dataset>
<dimension value="1">
<metric category="toys">
<data date=" 2010-01-01" sales=" 100.00"/>
<data date=" 2010-01-02" sales=" 210.00"/>
</metric>
</dimension>
<dimension value="1">
<metric category="food">
<data date=" 2010-01-01" sales=" 500.00"/>
</metric>
</dimension>
<dimension value="2">
<metric category="toys">
<data date=" 2010-01-03" sales=" 220.00"/>
</metric>
</dimension> </
dataset>
flatfile schema: falt file schema convert input text message xml:
<?xml version="1.0" encoding="utf-16"?>
<
xs:schema xmlns:b="http://schemas.microsoft.com/biztalk/2003" xmlns="http://testproject.ffsale" targetnamespace="http://testproject.ffsale" xmlns:xs="http://www.w3.org/2001/xmlschema">
<xs:annotation>
<xs:appinfo>
<schemaeditorextension:schemainfo namespacealias="b" extensionclass="microsoft.biztalk.flatfileextension.flatfileextension" standardname="flat file" xmlns:schemaeditorextension="http://schemas.microsoft.com/biztalk/2003/schemaeditorextensions"/>
<b:schemainfo standard="flat file" codepage="65001" default_pad_char="" pad_char_type="char" count_positions_by_byte="false" parser_optimization="speed" lookahead_depth="3" suppress_empty_nodes="false" generate_empty_nodes="true" allow_early_termination="false" early_terminate_optional_fields="false" allow_message_breakup_of_infix_root="false" compile_parse_tables="false" root_reference="root"/>
</xs:appinfo>
</xs:annotation>
<xs:element name="root">
<xs:annotation>
<xs:appinfo>
<b:recordinfo structure="delimited" child_delimiter_type="hex" child_delimiter="0xd 0xa" child_order="infix" sequence_number="1" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false"/>
</xs:appinfo>
</xs:annotation>
<xs:complextype>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<groupinfo sequence_number="0" xmlns="http://schemas.microsoft.com/biztalk/2003"/>
</xs:appinfo>
</xs:annotation>
<xs:element maxoccurs="unbounded" name="dataset">
<xs:annotation>
<xs:appinfo>
<b:recordinfo structure="delimited" child_delimiter_type="char" child_delimiter="," child_order="infix" sequence_number="1" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false"/>
</xs:appinfo>
</xs:annotation>
<xs:complextype>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<groupinfo sequence_number="0" xmlns="http://schemas.microsoft.com/biztalk/2003"/>
</xs:appinfo>
</xs:annotation>
<xs:element name="dimension" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldinfo justification="left" sequence_number="1"/>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="category" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldinfo justification="left" sequence_number="2"/>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="date" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldinfo justification="left" sequence_number="3"/>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="sales" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldinfo justification="left" sequence_number="4"/>
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complextype>
</xs:element>
</xs:sequence>
</xs:complextype>
</xs:element> </
xs:schema>
regards,
tariq majeed
please mark answer if helps
BizTalk Server > BizTalk Server General
Comments
Post a Comment