Home Page › Forums › BizTalk 2004 – BizTalk 2010 › Mapping sequential xml records . . .
- This topic has 3 replies, 1 voice, and was last updated 9 years, 1 month ago by
community-content.
-
AuthorPosts
-
-
September 20, 2006 at 8:42 PM #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!
-
September 21, 2006 at 11:49 AM #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" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" xmlns:userCSharp="http://schemas.microsoft.com/BizTalk/2003/userCSharp" 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>-
September 22, 2006 at 1:37 PM #15812
Thanks!! Works great.
-
September 27, 2006 at 7:14 AM #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.
-
-
-
-
AuthorPosts
- The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.