[xsl] Code re-use

Subject: [xsl] Code re-use
From: Rod Humphris - FLPTN <rod.humphris@xxxxxxxxxxxxxx>
Date: Fri, 28 Feb 2003 15:09:04 -0000
Hello, 

I wonder if anyone could help with this...

I need to filter, sort and page some data as I have done many times before,
this time if I can I would like to learn how to build generic templates that
are not coded to the specific data and which I can re-use. Here is my
example:

The data looks like this (typically about 3000 row elements):

<SpoolFilesList>
 <Results>
  <row JobName="WSO35DTAQ " JobUser="WAREHOUSE " JobNumber="018070"
UserData="CSCSO35   " SpoolName="PSO35R    " SpoolNumber="12"
SpoolStatus="*READY    " SpoolPages="1" OutputQueue="QNOPRT    "
SpoolDateTime="26-FEB-2003 14:05:16" InternalID="                " />

<row JobName="WSO35DTAQ " JobUser="WAREHOUSE " JobNumber="018070"
UserData="CSCSO35   " SpoolName="PSO35R    " SpoolNumber="14"
SpoolStatus="*READY    " SpoolPages="1" OutputQueue="QNOPRT    "
SpoolDateTime="26-FEB-2003 14:05:16" InternalID="                " />

<row JobName="WSO35DTAQ " JobUser="WAREHOUSE " JobNumber="018070"
UserData="CSCSO35   " SpoolName="PSO35R    " SpoolNumber="16"
SpoolStatus="*READY    " SpoolPages="1" OutputQueue="QNOPRT    "
SpoolDateTime="26-FEB-2003 14:05:16" InternalID="                " />

I first created dropdown boxes which offer the unique options for the
OutputQueue, SpoolName and SpoolStatus fields. The users can select from
these and I will pass their selections in as parameters.

My first task is to filter the data by their selections before I go on to
sort and page it. To date I would have done this on the basis of something
like (passing in a reference to all the row elements):

<xsl:template name="FilterNodes">
 <xsl:param name="NodesIn"/>
 <xsl:choose>
  <xsl:when test="$SpoolName!='All'">
   <xsl:copy-of select="$NodesIn[@SpoolName=$SpoolName"/>
  </xsl:when>
  Other <xsl:whens etc omitted
</xsl:template>

Which I could surely do better. What I would like is a template to which I
can pass a set of nodes and a set of parameters and it will pass me back the
data filtered by the parameters. This is as far as I have got:

<xsl:template match="Results">
 <xsl:call-template name="FilterResults">
  <xsl:with-param name="NodeList" select="row"/>
  <xsl:with-param name="ParamList"
select="document('')/*/xsl:param[@name='SpoolName' or @name='OutputQueue' or
@name='SpoolStatus']"/>
 </xsl:call-template>
</xsl:template>

this sends all the rows and the three parameters into template FilterResults
which is where it comes unstuck:

<xsl:template name="FilterResults">
 <xsl:param name="NodeList"/>
 <xsl:param name="ParamList"/>

 <xsl:variable name="ConditionList">
  <xsl:for-each select="$ParamList">[normalize-space(@<xsl:value-of
select="@name"/>)='<xsl:value-of select="."/>']</xsl:for-each>
 </xsl:variable>
<!--
$ConditionList now contains my xpath filter like this:
[normalize-space(@SpoolName)='WHR134PF'][normalize-space(@OutputQueue)='QNOP
RT'][normalize-space(@SpoolStatus)='*READY']
 but I can't use it, can I?
-->
</xsl:template>

I want to say something like this:  <xsl:copy-of
select="$NodeList{$ConditionList}"/>  but of course it doesn't work.

Can anyone suggest any way that I can do this, or a better approach?

Many thanks

Rod


Rod Humphris
PC Developer
Focus DIY Limited
Tel: 01761 416034 xt 581
email: rod.humphris@xxxxxxxxxxxxxx



**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the sender as soon as possible.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.focusdiy.co.uk
***************************************************************

________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs SkyScan
service. For more information on a proactive anti-virus service working
around the clock, around the globe, visit http://www.messagelabs.com
________________________________________________________________________

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


Current Thread