Home Page › Forums › BizTalk 2004 – BizTalk 2010 › Looping problem with mapper
- This topic has 10 replies, 1 voice, and was last updated 9 years, 4 months ago by
community-content.
-
AuthorPosts
-
-
May 27, 2008 at 6:28 AM #19762
Hello,
I need to make simple transformation to my message and I’m trying to make it with mapper, but with little success.
The scenario is:
xml I got as input is like:
<Root>
<Offer>
<Key>aaa</Key>
<field1>a1</field1>
<field2>b1</field2>
</Offer>
<Offer>
<Key>aaa</Key>
<field1>a2</field1>
<field2>b2</field2>
</Offer>
<Offer>
<Key>bbb</Key>
<field1>a3</field1>
<field2>b3</field2>
</Offer>
</Root>And the format I need to transform it is:
<Root>
<Offer>
<Key>aaa<Key>
<Line>
<Field1>a1</Field1>
<Field2>b1</Field2>
</Line>
<Line>
<Field1>a2</Field2>
<Field2>b2</Field2>
</Line>
</Offer>
<Offer>
<Key>bbb<Key>
<Line>
<Field1>a2</Field1>
<Field2>b3</Field2>
</Line>
</Offer>
</Root>So I need to make new Offer element for each distinct values in Key field and put those Field1 and Field2 under it.
Can I make this somehow with mapper or do I need to use custom xslt or something else?
I’m new with biztalk, so I dont know if this is simple task and I just dont know how to use that mapper right,
but I have tried to get this done some time now, so any help/suggestion is appreciated 🙂Woltor
-
May 27, 2008 at 7:53 AM #19765
Hi Woltor,
My mapper understanding level is 300 level at best, but I think there is a good chance that you can solve your problem using the out-of-the-box functoids. I would look into using the Table Looping and Table Extractor functoids. If that doesn’t work then you can definitely do it with custom XSLT. Hope this helps!
-
May 27, 2008 at 8:22 AM #19766
Hi –
You actually CAN do this with the mapper. I don;t have time to spell it out for you but the basic methodology is to use looping so that each line has ALL item iterations and you use the logicals to turn off the ones that are inappropriate for that iteration; i.e. generate a false unless the line items are equal to “this” item. The “this item” is going to be determined by an outer for each (looping).
-
May 27, 2008 at 4:30 PM #19774
Here is a custom Xslt that will perform the map required
<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“ method=“xml“ version=“1.0“ />
<xsl:key name=“OfferKey“ match=“Offer“ use =“Key“/>
<xsl:template match=“/“>
<xsl:apply-templates select=“/Root“ />
</xsl:template>
<xsl:template match=“/Root“>
<xsl:element name=“Root“>
<xsl:for-each select=“Offer“>
<xsl:variable name=“group“ select =“key(‘OfferKey’, Key)“ />
<xsl:if test=“generate-id($group[1]) = generate-id()“>
<xsl:element name=“Offer“>
<xsl:element name=“Key“>
<xsl:value-of select =“Key“/>
</xsl:element>
<xsl:for-each select=“$group“>
<xsl:element name=“Line“>
<xsl:element name=“Field1“>
<xsl:value-of select=“field1“/>
</xsl:element>
<xsl:element name=“Field2“>
<xsl:value-of select=“field2“/>
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:if>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>-
May 28, 2008 at 9:39 AM #19778
Once he implements custom XSLT, he loses the ability to maintain the map in the mapping tool, correct?
-
May 28, 2008 at 12:37 PM #19780
Yes, that is correct. The custom Xslt file overrides all content within the mapping grid.
Disadvantages: No GUI mapper and you have to learn Xslt
Advantages: Line by line debugging with breakpoints using Xslt, Handle more complicated mapping scenarios, More efficient maps, You can use templates, better structured output,
You can use Xslt maps for message validation-even in the pipeline by having a choice of output i.e. the original message or an error message
I still use the mapper but only for simple maps.
-
May 29, 2008 at 7:58 AM #19792
But doesn’t not using a mapping tool defeat the purpose of having a mapping tool?
-
May 29, 2008 at 12:40 PM #19797
Having one tool to do a job is fine, but if that tool can’t do what you want it to do then you need another.
I find with really complicated maps the Mapper is really hard to comprehend. Given a page of obtuse functoids and lines disappearing off the page, continual scrolling and opening functoids takes forever to untangle a map you have not seen. Some times you just cannot do what you want with the mapper.
I use the mapper for simple maps, straight field to field mapping, with a few simple functoids. When a map gets complicated I use Xslt – I find it much faster, more predictable, faster to debug, with more efficient Xslt.
-
May 30, 2008 at 7:33 AM #19808
1. But the tool can do what you want. So why use XSLT instead of the tool?
2. WIth more experience with the mapper, you get better at recognizing groups of functoids and what they do.
3. In writing pure XSLT, you have to copy your xpaths from another tool or type them, which is more prone to error.
4. On complicated schemas like Edifact and X12, you have segments and elements repeatedly reused throughout the document. Without the visual representation from the mapper, it becomes harder to that you have the right node.
So there are some good reasons to use the mapping tool.
-
May 30, 2008 at 10:29 AM #19814
On the plus side choosing XSLT instead of the mapper, I should acknowledge that there are several things that the Biztalk Mapper does not do easily. So from a capability standpoint, you can do certain things far more easily with the straight XSLT, as we see in this thread’s example. In my solution to preserving the graphical mapping, I would have had to cache keys and use external scripting – esentially using a lot of tricks. Greg’s XSLT solution is a far more elegant in directly solving the problem without tricks to get around limitations.
The latest issue of BizTalk HotRot has a detailed article on the Smart use of straight XSLT. There are a number of considerations to factor into the decision, such as performance, large file support, etc. I highly recommend to anyone interested in this thread to read the article.
Article by Scott Colestock on P28 of the current issue: http://cid-b6c859f7a5f75e63.skydrive.live.com/self.aspx/Public/Q2FY08_biztalk.pdf
Biztalk hotrod main site: http://biztalkhotrod.com/default.aspx
-
-
-
-
-
-
May 29, 2008 at 11:23 PM #19801
Hello
Thanks for the xsl, I got it working now 🙂
-Woltor
-
-
-
-
AuthorPosts
- The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.