Page 1 of 1

Handling repetition element in xml

Posted: Mon Nov 12, 2007 5:28 am
by valar_mathi
Hi Friends,

I am new to Datastage so pls help me in resolving this issue.

Input XML:

Code: Select all

<TAGS TAG_NAME="KK_ABC">
<A>1</A>
<B>703</B>
<C>G</C>
<A>2</A>
<B>701</B>
<C>G</C>
<A>3</A>
<B>698</B>
</TAGS>


Tags A, B and C are repeated multiple times in the input XML and i have to extract all these values and store into a table. Can anyone let me know how the values should be extracted?

I came to know that custom stylesheet should be used for this but i dont know how to customise the stylesheet and where should i place it in the unix.

Thanks in advance
Valarmathi

Posted: Mon Nov 12, 2007 6:40 am
by chulett
Need more information - what do your XPath expressions that you are using look like? Are they hand-crafted or did you import the metadata from your XML (or an xsd) so that DataStage built them for you? What does your target table look like, meaning what does the flattened output need to look like?

A 'custom stylesheet' does not go 'in UNIX' but rather under the Advanced tab on your Output link in any XML stage. Read Appendix B: Advanced Transformations in the XML PACK Designer Guide pdf in your Docs directory for all of the gory details, including how to capture the generated stylesheet that you would then modify and replace.

Handling repetition element in xml

Posted: Mon Nov 12, 2007 7:45 am
by valar_mathi
Thanks for your reply.
I imported the metadata from XML file. Header text from the XML should be loaded into parent table and body text should be loaded into a child table.


Code: Select all

[quote]<ENBELOPE>
   <ENBELOPE-HEADER>
      <GROUP_NAME>DETAALLOAD</GROUP_NAME>
      <Source>GOCRS1</Source>
      <H_DATE>2007-07-04</H_DATE>
   </ENBELOPE-HEADER>
   <ENBELOPE-BODY>

[quote]<TAGS NAME="AB">
<A>1</A>
<B>264</B>
<C>G</C>
<A>2</A>
<B>243</B>
<C>G</C>
<A>3</A>
<B>258</B>
<C>G</C>
</TAGS>[/quote]

</ENBELOPE-BODY>
</ENBELOPE>[/quote]


Repetition elements (A,B & C) exist in the body. I have to extract all the values of A, B & C and insert into the child table as individual records.

Handling repetition element in xml

Posted: Tue Nov 13, 2007 5:46 am
by valar_mathi
Can anyone help me in resolving this issue?

Posted: Tue Nov 13, 2007 6:23 am
by chulett
Well... thought you were going to go off and whip up a custom stylesheet, what happened to that effort?

Recognize the fact that you haven't said what your issue is, exactly - all you've said is what you have to do. What have you tried? What didn't work? Examples are always good. You'll need either two links or two separate jobs, one for the header / parent information and another for the detail / child information. Have you tried that and what did your output look like when you did?

Handling repetition element in xml

Posted: Tue Nov 13, 2007 7:01 am
by valar_mathi
Thanks for your reply

Designed the job like this to verify whether able to extract all the data from xml.

Folder Stage ------> XML Input --------> Sequential Stage

I set the TagName as key field as it is a repeating element and extracted the data. Its extracting only the first value of A, B & C ie. value of

Code: Select all

<A>1</A>
<B>264</B>
<C>G</C>


I am not able to extract all the values of A, B & C.
While importing the XML definition, selected only the first A, B & C fields. Do I have to make any changes here?

I am new to datastage so pls bear with me if i am wrong anywhere.

(We couldnt get the xsd file hence couldnt customise the stylesheet.)

Posted: Tue Nov 13, 2007 7:25 am
by chulett
First off, customizing the stylesheet has nothing to do with having (or not having) an xsd. Did you read the appendix I mentioned? There is a section there called Accessing the Generated XSLT Stylesheet which explain the rather simple steps required. I'm not positive but tend to agree with you that customizing that may very well be the appropriate solution. Perhaps if we all think happy thoughts, the spirit known as The Great Ostic will appear and give us guidance. :wink:

In the meantime, please post your XPath expressions.

Handling repetition element in xml

Posted: Tue Nov 13, 2007 8:07 am
by valar_mathi
Yes, I went through the document. It describes how to view the generated stylesheet in Job log view. I couldnt find where the generated file is placed and how it can be accessed.

Xpath expressions:
/ENBELOPE-HEADER/GROUP_NAME/text()
/ENBELOPE-HEADER/Source/text()
/ENBELOPE-HEADER/H_DATE/text()
/ENBELOPE-BODY/TAGS/@TAG_NAME
/ENBELOPE-BODY/TAGS/A/text()
/ENBELOPE-BODY/TAGS/B/text()
/ENBELOPE-BODY/TAGS/C/text()


TAG_NAME is repeated and within that A, B & C are also repeated.

Posted: Tue Nov 13, 2007 8:24 am
by chulett
:? You simply copy it to the clipboard from the log and place it anywhere you like. Then edit to your heart's content with your favorite editing tool. When done, I've already said where it goes back in the job.

If you are like me and XSLT illiterate :( enlist the help of someone who isn't. Explain the situation and ask them to adjust the XSLT accordingly. That's what I did back in the day when faced with this situation. They don't need to know a lick about DataStage in order to help with something like that.

Handling repetition element in xml

Posted: Tue Nov 13, 2007 8:31 am
by valar_mathi
Thank you so much. :)

I will try to get help...