Xml stage , for dynamic xml ip

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
harryhome
Participant
Posts: 112
Joined: Wed Oct 18, 2006 7:10 am

Xml stage , for dynamic xml ip

Post by harryhome »

I have a MQStage where xml data is getting loaded in Queue. Following Data is getting loaded in queue,(its like parent child data , where parent is 'SenderReference' and child 'CRTData') . There can be more than one child for a parent.

<SenderReference><RequestId>CG</RequestId><Identity>CG</Identity></SenderReference><CRTData><BusinessArea><id>1</id><name>CG</name><descriptionEn>CG</descriptionEn><date_time_updated/><updateUserLogin>ENG0025</updateUserLogin></BusinessArea><BusinessArea><id>2</id><name>MB</name><descriptionEn>MB</descriptionEn><date_time_updated/><updateUserLogin>ENG0025</updateUserLogin></BusinessArea></CRTData>


Following is the xsl code in xml stage , but its not giving o/p. plz help me on same


<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" />
<xsl:template match="SenderReference">
<xsl:value-of select="RequestId" />
<xsl:text>|</xsl:text>
<xsl:value-of select="Identity" />
<xsl:text>|</xsl:text>
</xsl:template>
<xsl:template match="CRTData">
<xsl:for-each select="BusinessArea">
<xsl:value-of select="id" />
<xsl:text>|</xsl:text>
<xsl:value-of select="name" />
<xsl:text>|</xsl:text>
<xsl:value-of select="descriptionEn" />
<xsl:text>|</xsl:text>
<xsl:value-of select="date_time_updated" />
<xsl:text>|</xsl:text>
<xsl:value-of select="updateUserLogin" />
<xsl:text disable-output-escaping="yes"></xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

Can we assume that there is higher level "root" element for these two nodes? If so, given this structure, and the SenderReference node only occurs once in the entire document, you could get away with having SenderReference columns on the same link as the CRT data. However, because they aren't nested nodes (ie...CRT "inside" of the SenderReference one), if the SenderReference information repeats multiple times, then they may as well be entirely unrelated nodes...... and you will need one link and table definition for SenderReference and another for the CRT data.....and then relate the data later.

Ernie
harryhome
Participant
Posts: 112
Joined: Wed Oct 18, 2006 7:10 am

Post by harryhome »

thanks for reply.

SenderReference is parent which will occur only once, and in side CRTData , which is a child BusinessArea can repeat n number of times.

For xml we can assume that there will be a higher node on the top of a parent and its childs.


The problem i m facing is , even if i send 1 row as input having 1 parent and 1 child , its shows me on input link as 2 rows!!!!!!!!!!!!!!!
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

That is correct... for the xml content that you cut and pasted above, there are two business areas... here it is again after I added some CRLF's to make it more easily readable...

<SenderReference>
<RequestId>CG</RequestId>
<Identity>CG</Identity>
</SenderReference>
<CRTData>
<BusinessArea>1
<name>CG</name>
<descriptionEn>CG</descriptionEn>
<date_time_updated/>
<updateUserLogin>ENG0025</updateUserLogin></BusinessArea>
<BusinessArea>2
<name>MB</name>
<descriptionEn>MB</descriptionEn>
<date_time_updated/>
<updateUserLogin>ENG0025</updateUserLogin>
</BusinessArea>
</CRTData>

Assuming that you've defined the meta data correctly, your output link probably has at least one column in it from the lowest node... look at the description properties... one of them is probably something like:
/<yourRoot>/CRTData/BusinessArea/name/text() ....and importantly, one of those columns has Key=yes (it's not a key, but the "repetition element").

The XMLInput Stage performs what I like to call "dynamic normalization" and thus returns two rows for this "relational" view of the xml document. Sounds like it's working perfectly. Should be one row "into" the XMLInput Stage and (for this xml sample) two rows out.

Ernie
Post Reply