Issue while creating an XML File

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
srds2
Premium Member
Premium Member
Posts: 66
Joined: Tue Nov 29, 2011 6:56 pm

Issue while creating an XML File

Post by srds2 »

I have a job with Below structure
Some Stages->XML Output Stage->XML Output Stage->XML Transformer Stage

Till the First XML Output Stage, When I have written the output to a file the below structure can be seen

Code: Select all

     <MainSubTag>
       <Tag1>Value1</Tag1>
        <Tag2>Value2</Tag2>
     </MainSubTag>
     <MainSubTag>
        <Tag1>Value3</Tag1>
        <Tag2>Value4</Tag2>
     </MainSubTag>
In the next XML Output Stage, I am getting the below output

Code: Select all

<MainTag>
     <MainSubTag>
         <Tag1>Value1</Tag1>
        <Tag2>Value2</Tag2>
     </MainSubTag>
</MainTag>
<MainTag>
     <MainSubTag>
        <Tag1>Value3</Tag1>
        <Tag2>Value4</Tag2>
     </MainSubTag>
</MainTag>
But, Actually I should get something like this,

Code: Select all

<MainTag>
     <MainSubTag>
         <Tag1>Value1</Tag1>
        <Tag2>Value2</Tag2>
     </MainSubTag>
     <MainSubTag>
        <Tag1>Value3</Tag1>
        <Tag2>Value4</Tag2>
     </MainSubTag>
</MainTag>
So, in the final XML Output Stage before writing to a XML Transformer, the root element is repeating for each sub element
srds2
Premium Member
Premium Member
Posts: 66
Joined: Tue Nov 29, 2011 6:56 pm

XSLT Support

Post by srds2 »

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
	<xsl:template match="/MainTag">
		<MainTag>
	<xsl:for-each select="MainSubTag">
		<MainSubTag>
		<xsl:apply-templates select="./*[not(name()='Tag2')]"/>
		</MainSubTag>
	</xsl:for-each>
		</MainTag>
	</xsl:template>

	<xsl:template match="MainSubTag">
		<MainSubTag>
			<xsl:apply-templates select="./@*[not(name()='Tag2')]"/>
		</Order>
	</xsl:template>
	<xsl:template match="node()|@*">
		<xsl:copy>
			<xsl:apply-templates select="node()|@*"/>
		</xsl:copy>
	</xsl:template>

</xsl:stylesheet>
This style sheet is being used in Final XML Transformer Stage.
lstsaur
Participant
Posts: 1139
Joined: Thu Oct 21, 2004 9:59 pm

Post by lstsaur »

What's your root element? Are you thinking that "MainTag" is your root element? Please post your XML document.
MrBlack
Participant
Posts: 125
Joined: Wed Aug 08, 2012 8:57 am

Post by MrBlack »

You say you job looks like this:

Code: Select all

Some Stages -> XML Output -> XML Output -> XML Transformer
I'm curious couldn't your job look like this with just a single XML Output stage:

Code: Select all

Some Stages -> XML Output -> XML Transformer
And then you would just adjust your XPath to write out your tags properly? Is there a reason for two XML Output stages?
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

+ 1 and also, why the XML Transformer? If you exclusively are doing things in xslt, that makes sense, but it shouldn't be necessary if you are using xmlOutput.

As for duplicated root elements, that generally happens when things aren't aggregating correctly. Check things like:

a) your aggregation setting inside the xmlOutput Stage
b) the node level where you have specified one column as a "key" (this is the repeating element and should be in the lowest repeating node of the set of nodes you are trying to write).

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
Post Reply