[xsl] How to simplify the xslt expression for multiple conditions

Subject: [xsl] How to simplify the xslt expression for multiple conditions
From: "Yang" <sfyang@xxxxxxxxxxxxx>
Date: Fri, 18 May 2001 09:35:26 +0800
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