Mapping sequential xml records . . .

Home Page Forums BizTalk 2004 – BizTalk 2010 Mapping sequential xml records . . .

Viewing 1 reply thread
  • Author
    Posts
    • #15769

      Is there a way to map xml data that is related by sequence instead of hierarchy (with no information in the sequential records to relate them)?  I have simplified an example:

      <Root><Record attrib1="r1data"/><NoteToRecord attrib1="n1data"/><NoteToRecord attrib1="n2data"/><Record attrib1="r2data"/><NoteToRecord attrib1="n3data"/><NoteToRecord attrib1="n4data"/></Root>

       

      To:

      <Root><Record attrib1="r1data"><NoteToRecord attrib1="n1data"/><NoteToRecord attrib1="n2data"/></Record><Record attrib1="r2data"><NoteToRecord attrib1="n3data"/><NoteToRecord attrib1="n4data"/></Record></Root>

       Thanks!

    • #15791

      You will need to use a custom Xslt.

      Here is an example that works with the examples above:

       <?xml version="1.0" encoding="UTF-16" ?>
       <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform&quot; xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var&quot; xmlns:userCSharp="http://schemas.microsoft.com/BizTalk/2003/userCSharp&quot; exclude-result-prefixes="msxsl var userCSharp" version="1.0">
        <xsl:output indent = "yes" omit-xml-declaration="yes" method="xml" version="1.0" />
       <xsl:template match="/">
        <xsl:apply-templates select="/Root" />
        </xsl:template>
       <xsl:template match="/Root">
       <Root>
        <xsl:for-each select="Record">
         <Record>
          <xsl:if test="@attrib1">
           <xsl:attribute name="attrib1">
            <xsl:value-of select="@attrib1" />
           </xsl:attribute>
          </xsl:if>
          <xsl:variable name="reset" select="userCSharp:Reset()"/>
          <xsl:for-each select="following-sibling::*">
           <xsl:if test="userCSharp:MapChild(local-name())">
            <NoteToRecord>
             <xsl:if test="@attrib1">
              <xsl:attribute name="attrib1">
               <xsl:value-of select="@attrib1" />
              </xsl:attribute>
             </xsl:if>
            </NoteToRecord>
           </xsl:if>
          </xsl:for-each>
         </Record>
        </xsl:for-each>
       </Root>
       </xsl:template>
      <msxsl:script language="C#" implements-prefix="userCSharp">
      <![CDATA[
      bool done = false;
      public void Reset()
      {
       done = false;
      }
      public bool MapChild(string nodename)
      {
       if (nodename == "Record")
       {
          done = true;
       }
       return !done;
      }
      ]]>
      </msxsl:script>
      </xsl:stylesheet>

      • #15812

        Thanks!! Works great.

        • #15863

          Seems you could have skipped this if you had defined your parsing schema as having 'NoteToRecord' element subordinate to the 'Record' element.

          i.e Record contains 0 or more NoteToRecord 

          This is assuming you are parsing. otherwise the generator fo the source XML could have stacked NoteToRecord subordinately.
           

           

Viewing 1 reply thread
  • The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.