none
Map question RRS feed

  • Question

  • Hi

    I have a schema looking like this :

    <xs:complexType name="_Data">

      <xs:attribute name="Header" type="xs:string" />

      <xs:attribute name="Date" type="xs:string" />

      <xs:attribute name="Name" type="xs:string" />

      <xs:attribute name="Value" type="xs:string" />

     </xs:complexType

     

    giving data like this
     

    <Data Header="AAA" date="2008-10-28" Name="a1" Value="1.0" />

    <Data Header="AAA" date="2008-10-28" Name="a2" Value="2.0" />

    <Data Header="AAA" date="2008-10-28" Name="a3" Value="3.0" />

    <Data Header="BBB" date="2008-10-28" Name="a1" Value="1.0" />

    <Data Header="BBB" date="2008-10-28" Name="a2" Value="2.0" />

    <Data Header="BBB" date="2008-10-28" Name="a3" Value="3.0" />

     

    I need to map it to at schema like this 

     

     

    <Data>

    <Header>AAA</Header>

    <date>2008-10-28</date>

    <Record>

    <Name>a1</Name>

    <Value>1.0</Value>

    <Name>a2</Name>

    <Value>2.0</Value>

    <Name>a3</Name>

    <Value>3.0</Value>

    </Record>

    <Header>BBB</Header>

    <date>2008-10-28</date>

    <Record>

    <Name>a1</Name>

    <Value>1.0</Value>

    <Name>a2</Name>

    <Value>2.0</Value>

    <Name>a3</Name>

    <Value>3.0</Value>

    </Record>

    </Data>

     
    where the header and date is only once.

    Please help

    Thank you
    hottoko

    Thursday, September 10, 2009 12:44 PM

Answers

  • Hi,

    I spend a little time to solve this challenger, and this is the solution that I make for you:

    http://cid-98a008f39b7bbf8e.skydrive.live.com/self.aspx/.Public/MapGroupDistinctFields.zip

    The Zip file has the input and output schemas that I try, the Map and two xml files (in and out samples)

    Basically I use this XSLT

    <xsl:element name="Data">
    <xsl:for-each select="Data[not(@Header=preceding-sibling::Data/@Header)]">
    <xsl:element name="Header"><xsl:value-of select="@Header" /></xsl:element>
    <xsl:element name="date"><xsl:value-of select="@date" /></xsl:element>
    <xsl:element name="Record">
      <xsl:call-template name="NameValueTemplate">
        <xsl:with-param name="param1" select="string(@Header)" />
      </xsl:call-template>
    </xsl:element>
    </xsl:for-each>
    </xsl:element>

    <xsl:template name="NameValueTemplate">
    <xsl:param name="param1" />
    <xsl:for-each select="//Data[@Header=$param1]">
    <xsl:element name="Name"><xsl:value-of select="@Name" /></xsl:element>
    <xsl:element name="Value"><xsl:value-of select="@Value" /></xsl:element>
    </xsl:for-each>
    </xsl:template>

    You may need some little changes for your schema requirements J


    Sandro Pereira - http://sandroasp.spaces.live.com/blog/ http://www.devscope.net/WhatWeDo/Integration/tabid/107/Default.aspx
    Thursday, September 10, 2009 10:02 PM
    Moderator

All replies

  • Hi,
    you can do this, using inline XSLT.

    Maybe you have to get the distinct values from Header see this sample: http://groups.google.com/group/microsoft.public.xsl/browse_thread/thread/8bc1702540f4afc5

    And then for all this distinct values select all element from thevalue, in this sample all element that have AAA in Header and then all BBB


    Sandro Pereira - http://sandroasp.spaces.live.com/blog/ http://www.devscope.net/WhatWeDo/Integration/tabid/107/Default.aspx
    Thursday, September 10, 2009 1:11 PM
    Moderator
  • Correct me if i misunderstood.

    your source schema does have the attribute values of Header and Date which you want to map for destination map. If yes then i guess it is possible through XSLT.
    Thanks, Raja
    Thursday, September 10, 2009 1:13 PM
  • yes you are correct, how do I use  using inline XSLT. ??

    Thank you !

    Thursday, September 10, 2009 1:15 PM
  • Here is pseudo code...You have to make better shape based on your requirements

    inline XSLT call template

    <xsl:template name="hottoko">
    <xsl:param name="Header" />   
    <xsl:variable name="var:v1"/>
                        <xsl:element name="Header">
                                    <xsl:value-of select="./@Header"/>
                             /xsl:element>

      </xsl:template>


    Thanks, Raja
    Thursday, September 10, 2009 1:28 PM
  • Hi,

    Your requirement is to map a flat schema to a catalog, i.e. mapping a flat file schema to a hierarchical schema, with proper grouping.

    Please take a look at Looping functoid - here is a detailed msdn documentation for the same.

    http://msdn.microsoft.com/en-us/library/aa577679(BTS.10).aspx 

    You can also take a look at this blog http://stevestechnotes.blogspot.com/2006/02/biztalk-mapper-looping-tricks.html 
    Ambuj Kumar (FTE - Microsoft BizTalk Server)
    Thursday, September 10, 2009 1:43 PM
  • Hi,

    I spend a little time to solve this challenger, and this is the solution that I make for you:

    http://cid-98a008f39b7bbf8e.skydrive.live.com/self.aspx/.Public/MapGroupDistinctFields.zip

    The Zip file has the input and output schemas that I try, the Map and two xml files (in and out samples)

    Basically I use this XSLT

    <xsl:element name="Data">
    <xsl:for-each select="Data[not(@Header=preceding-sibling::Data/@Header)]">
    <xsl:element name="Header"><xsl:value-of select="@Header" /></xsl:element>
    <xsl:element name="date"><xsl:value-of select="@date" /></xsl:element>
    <xsl:element name="Record">
      <xsl:call-template name="NameValueTemplate">
        <xsl:with-param name="param1" select="string(@Header)" />
      </xsl:call-template>
    </xsl:element>
    </xsl:for-each>
    </xsl:element>

    <xsl:template name="NameValueTemplate">
    <xsl:param name="param1" />
    <xsl:for-each select="//Data[@Header=$param1]">
    <xsl:element name="Name"><xsl:value-of select="@Name" /></xsl:element>
    <xsl:element name="Value"><xsl:value-of select="@Value" /></xsl:element>
    </xsl:for-each>
    </xsl:template>

    You may need some little changes for your schema requirements J


    Sandro Pereira - http://sandroasp.spaces.live.com/blog/ http://www.devscope.net/WhatWeDo/Integration/tabid/107/Default.aspx
    Thursday, September 10, 2009 10:02 PM
    Moderator
  • Hi

    Thank you very much !

    I'll have a go at it today.

    Hottoko
    Friday, September 11, 2009 6:02 AM

  • HI

    I forgot that the source xml has a xmlns attribute,

    his
    <Root xmlns="mymamespace"> 

    <Data Header="AAA" date="2008-10-28" Name="a1" Value="1.0" />

    <Data Header="AAA" date="2008-10-28" Name="a2" Value="2.0" />

    <Data Header="AAA" date="2008-10-28" Name="a3" Value="3.0" />

    <Data Header="BBB" date="2008-10-28" Name="a1" Value="1.0" />

    <Data Header="BBB" date="2008-10-28" Name="a2" Value="2.0" />

    <Data Header="BBB" date="2008-10-28" Name="a3" Value="3.0" />

    </Root> 

    How can I add the namespace in the inline xslt ?

    Thank you !

    Wednesday, September 16, 2009 12:31 PM
  • Hi,

    You can add namespace in inline xslt .
    Sample: <xsl:element name="p:a" namespace="something"/>

    Sandro Pereira - http://sandroasp.spaces.live.com/blog/ http://www.devscope.net/WhatWeDo/Integration/tabid/107/Default.aspx
    Wednesday, September 16, 2009 1:01 PM
    Moderator
  • Hi

    I tryed this
    <xsl:for-each select="//*[local-name()='Data' and namespace-uri()='http://myNameSpace'][not(@Header=preceding-sibling::Data/@Header)]">

    (and som other combinations :-) )

    by I can't get it to loop just the 2 times


    Wednesday, September 16, 2009 2:22 PM
  • Hi,

    Sorry, I do not understand you previous question

    “I forgot that the source xml has a xmlns attribute…”

    I think if you use this: <xsl:for-each select="//Data[not(@Header=preceding-sibling::Data/@Header)]">

    You don’t need to put the namespace


    Sandro Pereira - http://sandroasp.spaces.live.com/blog/ http://www.devscope.net/WhatWeDo/Integration/tabid/107/Default.aspx
    Wednesday, September 16, 2009 3:02 PM
    Moderator