RE: [xsl] filtering

Subject: RE: [xsl] filtering
From: "Daniel Heskia" <daniel@xxxxxxxxx>
Date: Tue, 2 Nov 2004 16:52:33 +0100
Thanks Jeni and Mukul.
I chose to adopt some of Jeni's version, since it required the least
modification to my own implementation, but it seems that Mukul's version is
to favour in the long run.

Thanks for the quick response :-)

Sincerely,
Daniel


-----Original Message-----
From: Mukul Gandhi [mailto:mukul_gandhi@xxxxxxxxx] 
Sent: 1. november 2004 15:52
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] filtering


Here is a generic solution I wrote! A downside though;
it relies on node-set function..

<?xml version="1.0" encoding="UTF-8"?>
<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 method="xml" indent="yes"
encoding="UTF-8"/>
	
<xsl:template match="/root">
  <root>
    <xsl:variable name="rtf">
       <xsl:for-each select="row">
	 <xsl:variable name="curr_row" select="."/>
	 <xsl:variable name="x">
	   <xsl:for-each select="column">
	     <xsl:if test="position() = /root/header/*">
	       <xsl:if test="normalize-space(.) = ''">
	         1
	       </xsl:if>
	     </xsl:if>
	   </xsl:for-each>
	 </xsl:variable>
	 <xsl:if test="not(contains($x, '1'))">
	   <success>
	     <xsl:for-each select="/root/header/*">
		<xsl:element name="{name()}">
		  <xsl:value-of select="$curr_row/column[position()
= current()]"/>
		</xsl:element>
	     </xsl:for-each>
	   </success>
	 </xsl:if>
       </xsl:for-each>
     </xsl:variable>
     <flow>
	<total_in><xsl:value-of select="count(row)"
/></total_in>
	<total_out><xsl:value-of select="count(row) -
count(msxsl:node-set($rtf)/*)" /></total_out>
     </flow>
     <xsl:copy-of select="msxsl:node-set($rtf)/*"/>
   </root>
</xsl:template>

</xsl:stylesheet>

Regards,
Mukul

--- Daniel Heskia <daniel@xxxxxxxxx> wrote:

> Hi.
> I am trying to filter out data sets that do not have
> any data in the column
> numbers specified in "header" of the xml.
> 
> The header specifies that columns 1, 2, 3 and 7 are
> crucial in this
> particular instance and must not be empty. The
> values differ from time to
> time (I cannot hardcode the numbers in the xsl), but
> the element names in
> "header" (AAA, BBB etc.) are static for this type of
> data).
> 
> I need to test if the column numbers specified in
> the header are non-empty
> for each each row. I have tried to assign the values
> of the header data to
> variables and do something like: for each row, if
> test not(column[$_aaa]='')
> create the element. This, however, I cannot get to
> work.
> 
> Does anyone have a good idea?
> 
> xml-input:
> 
> <root>
>   <header> 
>     <AAA>1</AAA>
>     <BBB>2</BBB>
>     <CCC>7</CCC>
>     <DDD>3</DDD>
>  </header>
>   <row>
>     <column>Dude Looks like a Lady</column>
>     <column>Local</column>
>     <column>28-10-2004</column>
>     <column>51,23</column>
>     <column />
>     <column>80563</column>
>     <column>IE000000004</column>
>   </row>
>   <row>
>     <column>Never Ending Story</column>
>     <column>Test</column>
>     <column>21-02-2003</column>
>     <column>51,23</column>
>     <column />
>     <column>80563</column>
>     <column />
>   </row>
> </root>
> 
> xml-output:
> Note 1 element filtered out because column 7 was
> empty
> 
> <root>
>   <flow>
>     <total_in>2</total_in>
>     <total_out>1</total_out>
>   </flow>
>   <success>
>     <AAA>Dude Looks Like a Lady</AAA>
>     <BBB>Local</BBB>
>     <CCC>IE000000004</CCC>
>     <DDD>28-10-2004</DDD>
>   </success>
> </root>



		
__________________________________
Do you Yahoo!?
Take Yahoo! Mail with you! Get it on your mobile phone.
http://mobile.yahoo.com/maildemo 

Current Thread