RE: [xsl] Multiple Filtering of rows based on attributes values

Subject: RE: [xsl] Multiple Filtering of rows based on attributes values
From: "Kamlesh Bafna" <Kamlesh.Bafna@xxxxxxxx>
Date: Fri, 15 May 2009 14:57:24 +0530
Hi Jagdishwar,

I am using the following xslt -
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
	<xsl:output indent="yes" method="xml"  encoding="UTF-8"
	omit-xml-declaration="yes" />

	<xsl:template match = "/">
		<SQLXMLExport>
			<xsl:apply-templates/>
		</SQLXMLExport>
	</xsl:template>

	<xsl:template match = "Rows">
		<Rows>
			<xsl:apply-templates select="Row"/>
		</Rows>
	</xsl:template>

	<xsl:template match = "Row" >
		<xsl:copy-of select="."/>
		<xsl:if test="./Field[@alias='ITEM_CODE']='PENEMR'">
			<xsl:variable name="ProdDeptId" select="./Field[@alias='PROD_DEPT_ID']"/>
			<xsl:variable name="Rows" select=".."/>
			<xsl:variable name="ArtPayRowPresent">
				<xsl:call-template name="IsArtPayRowPresent">
					<xsl:with-param name="Rows" select="$Rows"/>
					<xsl:with-param name="ProdDeptId" select="$ProdDeptId"/>
				</xsl:call-template>
			</xsl:variable>
			<xsl:if test="ArtPayRowPresent != ''">
				<!--TODO: Create a new node for ArtPay-->
			</xsl:if>
		</xsl:if>
	</xsl:template>

	<xsl:template name ="IsArtPayRowPresent">
		<xsl:param name="Rows"/>
		<xsl:param name="ProdDeptId" select="''"/>
		<xsl:for-each select="$Rows/Row">
			<xsl:if test="./Field[@alias='ITEM_CODE']='ARTPAY' and
./Field[@alias='PENSIONALBE']='Y' and
./Field[@alias='PROD_DEPT_ID']=$ProdDeptId">
				<xsl:value-of select="'Y'"/>
			</xsl:if>
		</xsl:for-each>
	</xsl:template>

</xsl:stylesheet>

I am expecting the following output file -
			<Rows>
				<Row>
					<Field alias="ITEM_CODE">NIEMR</Field>
					<Field alias="PENSIONALBE">N</Field>
					<Field alias="PROD_DEPT_ID">Task1</Field>
				</Row>
				<Row>
					<Field alias="ITEM_CODE">NIEME</Field>
					<Field alias="PENSIONALBE">N</Field>
					<Field alias="PROD_DEPT_ID">Task1</Field>
				</Row>
				<Row>
					<Field alias="ITEM_CODE">ARTPAY</Field>
					<Field alias="PENSIONALBE">Y</Field>
					<Field alias="PROD_DEPT_ID">Task2</Field>
				</Row>
				<Row>
					<Field alias="ITEM_CODE">ARTPAY</Field>
					<Field alias="PENSIONALBE">N</Field>
					<Field alias="PROD_DEPT_ID">Task1</Field>
				</Row>
				<Row>
					<Field alias="ITEM_CODE">PENEME</Field>
					<Field alias="PENSIONALBE">N</Field>
					<Field alias="PROD_DEPT_ID">Task1</Field>
				</Row>
				<Row>
					<Field alias="ITEM_CODE">PENEMR</Field>
					<Field alias="PENSIONALBE">N</Field>
					<Field alias="PROD_DEPT_ID">Task1</Field>
				</Row>
				<Row>
					<Field alias="ITEM_CODE">PENEMR</Field>
					<Field alias="PENSIONALBE">N</Field>
					<Field alias="PROD_DEPT_ID">Task2</Field>
				</Row>
				<Row>
					<Field alias="ITEM_CODE">PENEMR</Field>
					<Field alias="PENSIONALBE">N</Field>
					<Field alias="PROD_DEPT_ID">Task3</Field>
				</Row>
				<Row>
					<Field alias="ITEM_CODE">ARTPAY</Field>
					<Field alias="PENSIONALBE">Y</Field>
					<Field alias="PROD_DEPT_ID">Task1</Field>
				</Row>
				<Row>
					<Field alias="ITEM_CODE">ADVREC</Field>
					<Field alias="PENSIONALBE">N</Field>
					<Field alias="PROD_DEPT_ID">Task1</Field>
				</Row>
				<Row>
					<Field alias="ITEM_CODE">VATAMT</Field>
					<Field alias="PENSIONALBE">N</Field>
					<Field alias="PROD_DEPT_ID">Task1</Field>
				</Row>
				<-- This is the new node added as there was no row with Item code ARTPAT
and PROD_DEPT_ID as Task3-->
				<Row>
					<Field alias="ITEM_CODE">ARTPAY</Field>
					<Field alias="PENSIONALBE">N</Field>
					<Field alias="PROD_DEPT_ID">Task3</Field>
				</Row>
			</Rows>

Thanks
Kamlesh

-----Original Message-----
From: Jagdishwar B [mailto:jagdishwar.beemanati@xxxxxxxxx]
Sent: Friday, May 15, 2009 12:37 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Multiple Filtering of rows based on attributes values

Hi Kamlesh,
i tried to understand ur requirement,

can you also post the desired output.xml and the xslt with which you
already tried.




On Fri, May 15, 2009 at 11:44 AM, Kamlesh Bafna <Kamlesh.Bafna@xxxxxxxx>
wrote:
> Hi,
>
> I have the following input xml.
> My requirement is -
> 1. Select all row with ItemCode - 'PENEMR' & then get thier PROD_DEPT_ID
> 2.  For each PROD_DEPT_ID found above - Check atleast one row is present
> whose Item_Code is ARTPAY and same PROD_DEPT_ID. If not present then add
> a new row with ITEM_CODE as ARTPAY and PROD_DEPT_ID value same as
> PENEMR.
>
> I am using Microsoft .NET 3.0 xsl processor. I have written an xslt
> which loopes through the rows to find the row with ITEM_CODE as PENEMR
> and then another loop to identify the ARTPAY. However i think there is
> better way to do this through keys and requires some guidance on this.
>
> Also I am unable to find single Xpath to find row with Item Code as
> ART_PAY and Pensional as 'Y' and PROD_DEPT_ID as some variable value.
> Please help.
>
> Thanks
> Kamlesh
>
> INPUT XML -
>
> <Rows>
>    <Row>
>     <Field alias="ITEM_CODE">NIEMR</Field>
>     <Field alias="PENSIONALBE">N</Field>
>     <Field alias="PROD_DEPT_ID">Task1</Field>
>    </Row>
>    <Row>
>     <Field alias="ITEM_CODE">NIEME</Field>
>     <Field alias="PENSIONALBE">N</Field>
>     <Field alias="PROD_DEPT_ID">Task1</Field>
>    </Row>
>    <Row>
>     <Field alias="ITEM_CODE">ARTPAY</Field>
>     <Field alias="PENSIONALBE">Y</Field>
>     <Field alias="PROD_DEPT_ID">Task2</Field>
>    </Row>
>    <Row>
>     <Field alias="ITEM_CODE">ARTPAY</Field>
>     <Field alias="PENSIONALBE">N</Field>
>     <Field alias="PROD_DEPT_ID">Task1</Field>
>    </Row>
>    <Row>
>     <Field alias="ITEM_CODE">PENEME</Field>
>     <Field alias="PENSIONALBE">N</Field>
>     <Field alias="PROD_DEPT_ID">Task1</Field>
>    </Row>
>    <Row>
>     <Field alias="ITEM_CODE">PENEMR</Field>
>     <Field alias="PENSIONALBE">N</Field>
>     <Field alias="PROD_DEPT_ID">Task1</Field>
>    </Row>
>    <Row>
>     <Field alias="ITEM_CODE">PENEMR</Field>
>     <Field alias="PENSIONALBE">N</Field>
>     <Field alias="PROD_DEPT_ID">Task2</Field>
>    </Row>
>    <Row>
>     <Field alias="ITEM_CODE">PENEMR</Field>
>     <Field alias="PENSIONALBE">N</Field>
>     <Field alias="PROD_DEPT_ID">Task3</Field>
>    </Row>
>    <Row>
>     <Field alias="ITEM_CODE">ARTPAY</Field>
>     <Field alias="PENSIONALBE">Y</Field>
>     <Field alias="PROD_DEPT_ID">Task1</Field>
>    </Row>
>    <Row>
>     <Field alias="ITEM_CODE">ADVREC</Field>
>     <Field alias="PENSIONALBE">N</Field>
>     <Field alias="PROD_DEPT_ID">Task1</Field>
>    </Row>
>    <Row>
>     <Field alias="ITEM_CODE">VATAMT</Field>
>     <Field alias="PENSIONALBE">N</Field>
>     <Field alias="PROD_DEPT_ID">Task1</Field>
>    </Row>
>   </Rows>
>
>
>
>
>
>
>
>
> The information contained in this communication is intended solely for
> the use of the individual or entity to whom it is addressed and others
> authorized to receive it.   It may contain confidential or legally
> privileged information.   If you are not the intended recipient you are
> hereby notified that any disclosure, copying, distribution or taking any
> action in reliance on the contents of this information is strictly
prohibited
> and may be unlawful. If you have received this communication in error,
> please notify us immediately by forwarding this email to
> MailAdmin@xxxxxxxx and then delete it from your system.
>
> Ness technologies is neither liable for the proper and complete
> transmission of the information contained in this communication nor for
> any delay in its receipt.
>
>



--

Jagdishwar B.









The information contained in this communication is intended solely for
the use of the individual or entity to whom it is addressed and others
authorized to receive it.   It may contain confidential or legally
privileged information.   If you are not the intended recipient you are
hereby notified that any disclosure, copying, distribution or taking any
action in reliance on the contents of this information is strictly prohibited
and may be unlawful. If you have received this communication in error,
please notify us immediately by forwarding this email to
MailAdmin@xxxxxxxx and then delete it from your system.

Ness technologies is neither liable for the proper and complete
transmission of the information contained in this communication nor for
any delay in its receipt.

Current Thread