Home Page › Forums › BizTalk 2004 – BizTalk 2010 › Simple Mapper Question
- This topic has 1 reply, 1 voice, and was last updated 9 years, 6 months ago by
community-content.
-
AuthorPosts
-
-
November 20, 2006 at 1:09 PM #16460
I'm sure the solution is a simple one, but I just can't figure it out. I have a flatfile with data that looks like this:
A,1
A,2
A,3
B,4
C,5
C,6And the XML that I want as output is:
<Parent Value="A">
<Child Value="1"/>
<Child Value="2"/>
<Child Value="3"/>
</Parent>
<Parent Value="B"/>
<Child Value="4"/>
</Parent>
<Parent Value="C">
<Child Value="5"/>
<Child Value="6"/>
</Parent>I have the document specifications, but I just can't think of how to make this work in the mapper. Can you clue me in?
-
November 20, 2006 at 2:07 PM #16462
Depends on what type of data A,B and C are.
If they are a small set of known data items that seldom changes then you could use condition functoids
e.g. if firstfield = "A"
This would hardcode the values A, B, and C into the map.If A,B, and C are part of a large set that does change, i.e. you don't want to hardcode them into the map,
then you need to use a custom Xslt with Muenchian grouping
e.g.<?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" exclude-result-prefixes="msxsl" version="1.0">
<xsl:output indent="yes" omit-xml-declaration="yes" version="1.0" method="xml" />
<xsl:key name="recordkey" match="/root/record" use="firstfield"/>
<xsl:template match="/">
<xsl:apply-templates select="/root" />
</xsl:template>
<xsl:template match="/root">
<root>
<xsl:for-each select="record">
<xsl:variable name="group" select="key('recordkey', firstfield)"/>
<xsl:if test="generate-id($group[1]) = generate-id()">
<Parent>
<xsl:attribute name="Value">
<xsl:value-of select="firstfield"/>
</xsl:attribute>
<xsl:for-each select="$group">
<Child>
<xsl:attribute name="Value">
<xsl:value-of select="secondfield"/>
</xsl:attribute>
</Child>
</xsl:for-each>
</Parent>
</xsl:if>
</xsl:for-each>
</root>
</xsl:template>
</xsl:stylesheet>
-
-
AuthorPosts
- The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.