Page 1 of 1

Issue while creating an XML File

Posted: Thu Jul 25, 2013 3:51 pm
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

XSLT Support

Posted: Thu Jul 25, 2013 5:53 pm
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.

Posted: Fri Jul 26, 2013 9:57 am
by lstsaur
What's your root element? Are you thinking that "MainTag" is your root element? Please post your XML document.

Posted: Wed Jul 31, 2013 9:15 am
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?

Posted: Wed Jul 31, 2013 12:05 pm
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