Page 1 of 1

use of "if" in XML Write task

Posted: Wed Oct 16, 2013 2:24 pm
by SeanC
I'm using the XML Write task to generate an xml document from a rowset retrieved from a database query. There are elements that I want to appear in my output only if certain conditions are met. I would like to use an "if" inside the xml write prior to generating the element, but it seems to operate differently when inside the xml write than under normal project flow. Namely, it has a "test" attribute as opposed to the usual "condition" attribute and for the life of me I can't figure out what it wants in that test attribute. For example, my code goes something like this:
Code: Select all
		<xmlWrite outputFile="${system.job.workspace}/output.xml" defaultTrim="right" outputFileVariable="OutputFile" version="1.0">
			<header><?xml version="1.0" encoding="UTF-8" ?></header>
			<element name="vendors">
				<attribute name="xmlns" value="http://www.stryker.com/party" />
				<forEach inputRowSetVariable="${ResultSet}">
					<element name="vendor">
						<element name="name" value="${ResultSet[Supplier_Name]}" />
						<element name="directFlag" value="${ResultSet[Direct_Flag]}" />
						<element name="activeStatus" value="${ResultSet[Active_Status_MW]}" />
					</element>
				</forEach>
			</element>
		</xmlWrite>
I would like to have the element "directFlag" only appear in the output if its value is "true". When I try adding that I get an error:

[8003 - xmlWrite] Invalid value '${ResultSet[Direct_Flag] == 'true'}' for attribute 'test' in element 'if'

here's the code:
Code: Select all
		<xmlWrite outputFile="${system.job.workspace}/output.xml" defaultTrim="right" outputFileVariable="OutputFile" version="1.0">
			<header><?xml version="1.0" encoding="UTF-8" ?></header>
			<element name="vendors">
				<attribute name="xmlns" value="http://www.stryker.com/party" />
				<forEach inputRowSetVariable="${ResultSet}">
					<element name="vendor">
						<element name="name" value="${ResultSet[Supplier_Name]}" />
						<if test="${ResultSet[Direct_Flag] == &apos;true&apos;}">
							<element name="directFlag" value="${ResultSet[Direct_Flag]}" />
						</if>
						<element name="activeStatus" value="${ResultSet[Active_Status_MW]}" />
					</element>
				</forEach>
			</element>
		</xmlWrite>
I've tried lots of different values for the test clause but nothing seems to work, including simply entering "${true}". Can someone explain how this is used?

Thanks!

Sean

Re: use of "if" in XML Write task

Posted: Thu Oct 17, 2013 5:03 pm
by Support_Rick
Sean,

The XML If Condition was originally designed for Header/Detail relationships. Like the following:
Code: Select all
<forEach inputRowSetVariable="${details}">
	<if test="${details["TDPON"]} eq ${headers["THPON"]}">
		<element name="DocShpLineItem">
			<attribute name="ContainerQuantity" value="${details["TDCONQTY"]}" />
			<attribute name="CommodityCode" value="${details["TDCOMCDE"]}" />
			<attribute name="SKUNumber" value="${details["TDITM"]}" />
			<attribute name="Description" value="${details["TDDES"]}" />
		</element>
	</if>
</forEach>
Conditional Element statements are being considered for a future release.

Re: use of "if" in XML Write task

Posted: Thu Oct 17, 2013 7:58 pm
by SeanC
Ok. Thank you for the follow-up. I think I can find some other ways to work around this in the source query.