[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

How to simplify the xslt expression for multiple condi

Subject: How to simplify the xslt expression for multiple conditions
From: "Yang" <sfyang@xxxxxxxxxxxxx>
Date: Fri, 18 May 2001 09:35:26 +0800
xsl multiple filter
Hi,  Jeni,  I hope you can help me on this;

I am addressing a  problem as follows;

   **to  rank each salesperson of each store based on the sales amount on
each day for the given month **

and find out I have to repeatedly apply the following lengthy and tedious
expression for multiple filter conditions
to the xslt codes.

[not(string($month)) or substring(@SalesOrderNo,10, 2) = $month]
[not(string($dayID)) or substring(@SalesOrderNo,12, 2) = $dayID]
[not(string($timeID)) or substring(substring-after(@CreateDate,'T'),1,2) =
$timeID]
[not(string($salesID)) or normalize-space(@SalesCode)=$salesID]
[not(string($customerID)) or normalize-space(@CustomerCode)=$customerID]
[not(string($storeID)) or normalize-space(@StoreCode)=$storeID]
[not(string($salenoID)) or normalize-space(@SalesOrderNo)=$salenoID]

As this piece of filter expression has to be hard-wired with each key
function and sort function(it
will not function correctly if using variable) , it concerns
me the  maintenance problems whenever new conditions have to be added.

I would like to know is there a smart way  to show me how to keep this
coding update easily and cleanly.

Thanks any help in advance.

Sun-fu Yang,

sfyang@xxxxxxxxxxxxx



**** fyi - a piece of  the  my xsl with the multiple filter condition
expressions  ***

 <xsl:key name="dailySales" match="z:row" use="substring(@SalesOrderNo,12,
2)" />
 <xsl:key name="storeSales" match="z:row"
use="concat(substring(@SalesOrderNo,12, 2),':',@StoreCode)" />
 <xsl:key name="dailySalesP" match="z:row"
use="concat(substring(@SalesOrderNo,12, 2),':',@StoreCode,':',@Salesperson)"
/>

<xsl:for-each select="$MSource[@SalesOrderNo =
key('dailySales',substring(@SalesOrderNo,12, 2))
[not(string($month)) or substring(@SalesOrderNo,10, 2) = $month]
[not(string($dayID)) or substring(@SalesOrderNo,12, 2) = $dayID]
 [not(string($timeID)) or substring(substring-after(@CreateDate,'T'),1,2) =
$timeID]
[not(string($salesID)) or normalize-space(@SalesCode)=$salesID]
[not(string($customerID)) or normalize-space(@CustomerCode)=$customerID]
[not(string($storeID)) or normalize-space(@StoreCode)=$storeID]
[not(string($salenoID)) or normalize-space(@SalesOrderNo)=$salenoID]
[1]/@SalesOrderNo]">
<xsl:sort select="substring(@SalesOrderNo,12, 2)" order="ascending"
data-type="number"/>

<xsl:variable name="thisPP" select="substring(@SalesOrderNo,12, 2)"/>
<xsl:variable name="datas" select="key('dailySales',$thisPP)
[not(string($month)) or substring(@SalesOrderNo,10, 2) = $month]
[not(string($dayID)) or substring(@SalesOrderNo,12, 2) = $dayID]
 [not(string($timeID)) or substring(substring-after(@CreateDate,'T'),1,2) =
$timeID]
[not(string($salesID)) or normalize-space(@SalesCode)=$salesID]
[not(string($customerID)) or normalize-space(@CustomerCode)=$customerID]
[not(string($storeID)) or normalize-space(@StoreCode)=$storeID]
[not(string($salenoID)) or normalize-space(@SalesOrderNo)=$salenoID]
"/>

<xsl:for-each select="$datas
             [@SalesOrderNo =
key('storeSales',concat($thisPP,':',@StoreCode))
[not(string($month)) or substring(@SalesOrderNo,10, 2) = $month]
[not(string($dayID)) or substring(@SalesOrderNo,12, 2) = $dayID]
 [not(string($timeID)) or substring(substring-after(@CreateDate,'T'),1,2) =
$timeID]
[not(string($salesID)) or normalize-space(@SalesCode)=$salesID]
[not(string($customerID)) or normalize-space(@CustomerCode)=$customerID]
[not(string($storeID)) or normalize-space(@StoreCode)=$storeID]
[not(string($salenoID)) or normalize-space(@SalesOrderNo)=$salenoID]
[1]/@SalesOrderNo]">

<xsl:sort select="sum(key('storeSales',concat($thisPP,':',@StoreCode))
[not(string($month)) or substring(@SalesOrderNo,10, 2) = $month]
[not(string($dayID)) or substring(@SalesOrderNo,12, 2) = $dayID]
 [not(string($timeID)) or substring(substring-after(@CreateDate,'T'),1,2) =
$timeID]
[not(string($salesID)) or normalize-space(@SalesCode)=$salesID]
[not(string($customerID)) or normalize-space(@CustomerCode)=$customerID]
[not(string($storeID)) or normalize-space(@StoreCode)=$storeID]
[not(string($salenoID)) or normalize-space(@SalesOrderNo)=$salenoID]
/@TotalSalesAmt)" order="descending" data-type="number"/>

<xsl:variable name="storedatas"
select="key('storeSales',concat($thisPP,':',@StoreCode))
[not(string($month)) or substring(@SalesOrderNo,10, 2) = $month]
[not(string($dayID)) or substring(@SalesOrderNo,12, 2) = $dayID]
 [not(string($timeID)) or substring(substring-after(@CreateDate,'T'),1,2) =
$timeID]
[not(string($salesID)) or normalize-space(@SalesCode)=$salesID]
[not(string($customerID)) or normalize-space(@CustomerCode)=$customerID]
[not(string($storeID)) or normalize-space(@StoreCode)=$storeID]
[not(string($salenoID)) or normalize-space(@SalesOrderNo)=$salenoID]
"/>
<storename>
<xsl:attribute name="amt"><!-- store amount  -->
       <xsl:value-of
select="sum($storedatas/@TotalSalesAmt)"/></xsl:attribute>
<xsl:value-of select="@StoreCode"/>

<xsl:for-each select="$storedatas
             [@SalesOrderNo =
key('dailySalesP',concat($thisPP,':',@StoreCode,':',@Salesperson))
[not(string($month)) or substring(@SalesOrderNo,10, 2) = $month]
[not(string($dayID)) or substring(@SalesOrderNo,12, 2) = $dayID]
 [not(string($timeID)) or substring(substring-after(@CreateDate,'T'),1,2) =
$timeID]
[not(string($salesID)) or normalize-space(@SalesCode)=$salesID]
[not(string($customerID)) or normalize-space(@CustomerCode)=$customerID]
[not(string($storeID)) or normalize-space(@StoreCode)=$storeID]
[not(string($salenoID)) or normalize-space(@SalesOrderNo)=$salenoID]
[1]/@SalesOrderNo]">

<xsl:sort
select="sum(key('dailySalesP',concat($thisPP,':',@StoreCode,':',@Salesperson
))
[not(string($month)) or substring(@SalesOrderNo,10, 2) = $month]
[not(string($dayID)) or substring(@SalesOrderNo,12, 2) = $dayID]
 [not(string($timeID)) or substring(substring-after(@CreateDate,'T'),1,2) =
$timeID]
[not(string($salesID)) or normalize-space(@SalesCode)=$salesID]
[not(string($customerID)) or normalize-space(@CustomerCode)=$customerID]
[not(string($storeID)) or normalize-space(@StoreCode)=$storeID]
[not(string($salenoID)) or normalize-space(@SalesOrderNo)=$salenoID]
/@TotalSalesAmt)" order="descending" data-type="number"/>

<salesname><xsl:attribute name="amt">
<xsl:value-of
select="sum(key('dailySalesP',concat($thisPP,':',@StoreCode,':',@Salesperson
)
[not(string($month)) or substring(@SalesOrderNo,10, 2) = $month]
[not(string($dayID)) or substring(@SalesOrderNo,12, 2) = $dayID]
 [not(string($timeID)) or substring(substring-after(@CreateDate,'T'),1,2) =
$timeID]
[not(string($salesID)) or normalize-space(@SalesCode)=$salesID]
[not(string($customerID)) or normalize-space(@CustomerCode)=$customerID]
[not(string($storeID)) or normalize-space(@StoreCode)=$storeID]
[not(string($salenoID)) or normalize-space(@SalesOrderNo)=$salenoID]
/@TotalSalesAmt)"/></xsl:attribute>

<xsl:value-of select="@Salesperson"/></salesname>

</xsl:for-each>
</storename>
</xsl:for-each>
</xsl:for-each>






 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.