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

Fwd: Dynamic template select criteria; params & variab

Subject: Fwd: Dynamic template select criteria; params & variables
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 21 Aug 2002 14:44:43 +0100
dynamic template
[Forwarded on behalf of John Potter, who's having trouble posting to
 the list]

-----------------------------------

Dynamic template select criteria; params & variables

OK - After searching around a bit more, I've figured out that you're not
allowed to create dynamic XPath expressions but that dynamic predicates are
allowed...

Can anyone tell me why (from the example I submitted earlier) this isn't
working for me (no error but I get back all items whether they match the
criteria or not.

***************************

<xsl:variable name="test" select="'contains($color_criteria, @color) and
contains($letter_criteria, @letter)'"/>

<xsl:apply-templates select="records/record[$test]"/>

***************************

Hardcoding the entire select clause works as I would think it should...

<xsl:apply-templates 
                select="records/record[contains($color_criteria, @color) and
contains($letter_criteria, @letter)]"/>

This has got to be a fairly routine task.
                
Thanks.

John Potter

-----Original Message-----
From: John Potter 
Sent: Monday, August 19, 2002 2:09 PM
To: 'xsl-list@xxxxxxxxxxxxxxxx'
Subject: Dynamic template select criteria; params & variables


Hello:

I've been playing around with XSLT for the past couple months with good
results but have run into something that I'm having trouble getting around.

Essentially, I want to be able to pass in several values as parameters and
filter my output based on those values.

My initial thought was to create a variable, check the parameters one by one
and build the select criteria (specifically the predicates).  The content of
that variable would get placed in the apply-templates statement (e.g.
<xsl:apply-template select="$main_select_clause"/>).

I've got two problems - building the contents of the variable (I know - it's
more like a constant) and then getting the apply-template to work w/ the
variable (even if I build a simple variable w/ hard-coded values).

Am I missing something obvious?

You'll find a simplified example of what I'm trying to accomplish below.

Thanks.

John Potter

****************************************************************
Parser Info

Vendor: Microsoft
Vendor URL: http://www.microsoft.com

****************************************************************
xml file

<?xml version="1.0"?>

<records>
        <record num="1" letter="A" color="blue"/>
        <record num="2" letter="B" color="blue"/>
        <record num="3" letter="C" color="green"/>
        <record num="4" letter="D" color="yellow"/>
</records>

****************************************************************
xslt file

<?xml version="1.0"?>

<xsl:stylesheet 
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

        <xsl:output method="html"/>

        <xsl:param name="letter_criteria" select="'B'"/>
        <xsl:param name="color_criteria" select="'blue'"/>

        <xsl:variable name="main_select_clause"/>

<xsl:template match="/">
        <html>
        <body>
        <table>
                <!-- Build Dynamic select statement - $main_select_clause
-->
                <!-- May have no predicate, may have 1, may have more than
one             -->
                <!-- Need to check 
                (string-length((normalize_space(criteria params)) > 0)  -->

                <!--    $main_select_clause = "records/record"
-->
                <!--    test length of each criteria            -->
                <!--    append predicate if appropriate []      -->

                <!--    <xsl:apply-template select="$main_select_clause"/>
-->

                <xsl:apply-templates 
                select="records/record[contains($letter_criteria,
@letter)][contains($color_criteria, @color)]"/>

        </table>
        </body>
        </html>
</xsl:template>

<xsl:template match="records/record">

        <tr>
                <td><xsl:value-of select="@num"/></td>
                <td><xsl:value-of select="@letter"/></td>
                <td><xsl:value-of select="@color"/></td>
        </tr>

</xsl:template>

</xsl:stylesheet>

****************************************************************



----


 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.