views:

251

answers:

1

I've got a situation where my BizTalk map is not extracting data from input XML correctly.

The input schema looks like this:

Sequence

  A 

  B

All 3 of those nodes on the XSD have min 0, max unbounded.

So here's a sample input file fragment:

<A>1</A>
<B>hi</B>
<A>2</A>
<B>there</B>

Now my map takes this data and calls stored procs to insert data into a table. I'm getting "hi" for field B for both A of 1 and A of 2. That's incorrect.

I traced the problem to the map. The XSLT generated does a foreach on A, and then goes to grab value B but always grabs the first B.

So anyone have any tips for modifying either the input schema or the map to get this to work correctly?

+2  A: 

If you need to group A and B items togethers, you could change the schema is to create a wrapper element, so your schema would look like:

<xs:element name="wrapper">
  <xs:complextype>
    <xs:sequence>
      <xsl:element name="A" type="xs:string" minoccur="1" maxoccur="1"/>
      <xsl:element name="B" type="xs:string" minoccur="1" maxoccur="1" />
    </xs:sequence>
  </xs:complextype>
</xs:element>

Then you could loop through wrapper elements and get the A and B elements. But I'm not sure if that is what you're looking for.

The other option is to work within XSLT Call-templates. Using A and the current iteration of A, then when you get B you actually B[i], where i is the current iteration.

Wagner Silveira
Great suggestion. I will try it out. I'm just wondering if I need the 'wrapper' one at all. Doesn't the sequence element serve as a wrapper? In BizTalk I can specify min 0, max unbounded at that level, and then min 1 max 1 at A and B. I gave it a quick try and it completely changed the output of my transform.
Krip
It's a good suggestion indeed, and you could at least mod him up or accept the answer. There are too many people on SO already who just take answers and run.
xcut
Don't worry xcut, I'm not running away. I will certainly give credit where credit is due. I'm still trying to solve this in the BizTalk context and that is the criteria for me 'modding him up'. I'm unable to add a wrapper in and have it correctly parse the input file using the revised schema, let alone run the map to do the transform afterwards. This is because if I add a wrapper element I must indicate what 'text' I'm looking for, how it's delimited, etc., so at the moment while this is a good thought it's not working for me.-Krip
Krip
Hi Krip, based on your code snippet, I've assumed that your elements were at the root element, if you've already have another element wrapping it around, seems like you only need the max occurs to 1, as you suggested. You still need the source system to populate it properly, and now you will have repeating elements, which means that you will probably require a Looping functiod to have the data from the source schema to the destination schema correctly mapped. I hope this helps.
Wagner Silveira
Just to mention another option: How important is the map visibility within your project? You could consider taking the ´manual approach´ and write your desired XSLT in another editor. This will limit your options in ´functoid´ usages (although with some looking at the generated one, you can do those aswell). Writing native XSLT is not something you should do if you have little to no experience in it, but someone close might?ps: foreach in XSLT is rarely needed, a template-match is often a better choise in performance for the XSLT.
Marvin Smit