xsl:if or xsl:choose to filter a database and call a templat
Posted: Thu Feb 12, 2009 6:04 am
Eeeuuuureeekka! Hey George. I got it.
I knew that your input had placed me near the goal. I ran trials until I settled for this xslt:
code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:regex="http://exslt.org/regular-expressions"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:param name="filter" select="'EWR'"/>
<xsl:template match="/">
<html>
<head>
<title>Special Airline Fares List</title>
</head>
<body>
<h1>Special Fares List</h1>
<xsl:for-each select="XML/item">
<xsl:if test="contains(description, $filter)">
<xsl:call-template name="q" />
</xsl:if>
</xsl:for-each>
</body>
</html>
</xsl:template>
<xsl:template name="q" match="item">
<p>
<xsl:apply-templates select="pubDate"/>
<xsl:apply-templates select="title"/>
<xsl:apply-templates select="link"/>
<xsl:apply-templates select="description"/>
</p>
</xsl:template>
<xsl:template match="pubDate">
<br /><span style="color:#991111">
<xsl:value-of select="." />
</span><br />
</xsl:template>
<xsl:template match="title">
<span style="color:#2A7B39">
<xsl:value-of select="." />
</span><br />
</xsl:template>
<xsl:template match="link">
<span style="color:#636763">
<a href="{.}">
<xsl:value-of select="." />
</a>
</span><br />
</xsl:template>
<xsl:template match="description">
<span style="color:#111111">
<xsl:value-of select="." />
</span><br /><br />
</xsl:template>
</xsl:transform>
which does precisely what people need it to do. Now I can move to the next hair pulling, forehead slapping project: passing the param in from a form.
Again, George, thank you.
Steve
Hello;
I am teaching myself to capture a form variable and pass it via param to xslt where form input will filter an xml database and transform the results for display on the xhtml document. It seems my task is complicated because I do not want to return just the node text but all of the child nodes text so the user can have the information and link to proceed further.
Here is a snippet from the xml:
code:
<item>
<pubDate>Tue, 20 Jan 2009 14:12:00 UT</pubDate>
<title>Air France Airlines DE Specials 90120</title>
<link>http://airtravelcenter.com/aff/air-fran ... .htm</link>
<description>PREIS IM EUR, Hin und Ruckflug inkl Steuern Gebuhren, Buchungszeitraum ab sofort bis 17 Feb, Preise ab nach Hamburg: Sao Paolo 595, Rio de Janeiro 640, Caracas 590, Mexiko City 589, Buenos Aires 877, Bogota 650, Santiago de Chile 927, Havanna 488, Saint Martin 721, Peking 491, Shanghai 491, Hongkong 605, Seoul 535, Singapur 527, Tokio 674, Osaka 634, Nagoya 693, Mumbai 502, Delhi 502, Chennai 522, Bangalore 519, Antananarivo 998, Dubai 452, Amman 475.</description>
</item>
<item>
<pubDate>Tue, 03 Feb 2009 12:18:00 UT</pubDate>
<title>Air France Airlines SE Specials 90203</title>
<link>http://airtravelcenter.com/aff/air-fran ... .htm</link>
<description>Prices in SEK, Return Flights, Tax Included, BOOK BY 16 Feb, Depart Stockholm TO: Paris 1 395, Nice 1 695, Toulouse 2 295, Rome 1 695, Madrid 1 695, Barcelona 1 695, Geneva 1 695, Malaga 1 695, New York 3 670, Chicago 4 155, Miami 4 630, Los Angeles 5 030, Mexico City 6 565, Bogota 8 300, Buenos Aires 8 065, Caracas 7 400, Sao Paulo 6 270, Rio de Janeiro 6 370, Beijing 4 480, Shanghai 4 830, Hong Kong 6 000, Tokyo 6 405, Hanoi 8 290, Cairo 4 380, Dubai 4 640, Beirut 5 290, Johannesburg 6 375, Dakar 8 420, Mauritius 7 815, Santo Domingo 7 860, Havana 7 875, Seychelles 8 285, Saint Marteen 8 440.</description>
</item>
and here is the xslt:
code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:regex="http://exslt.org/regular-expressions"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:template match="XML">
<html>
<head>
<title>Special Airline Fares List</title>
</head>
<body>
<h1>Special Fares List</h1>
<xsl:apply-templates/>
</body>
</html>
<xsl:call-template name="query"/>
</xsl:template>
<xsl:template name="query" match="query">
<xsl:for-each select="XML/item/*">
For now, I am just trying to type in what would be passed in from the form, just to get my brain wrapped around this part. I will tackle the javascript portion once I have this filter working.
<xsl:choose>
<xsl:when test="???">
<xsl:call-template name="q"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>EWR not found</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
<xsl:template name="q" match="item">
<p>
<xsl:apply-templates select="pubDate"/>
<xsl:apply-templates select="title"/>
<xsl:apply-templates select="link"/>
<xsl:apply-templates select="description"/>
</p>
</xsl:template>
<xsl:template match="pubDate">
<br /><span style="color:#991111">
<xsl:value-of select="." />
</span><br />
</xsl:template>
<xsl:template match="title">
<span style="color:#2A7B39">
<xsl:value-of select="." />
</span><br />
</xsl:template>
<xsl:template match="link">
<span style="color:#636763">
<a href="{.}">
<xsl:value-of select="." />
</a>
</span><br />
</xsl:template>
<xsl:template match="description">
<span style="color:#111111">
<xsl:value-of select="." />
</span><br /><br />
</xsl:template>
</xsl:transform>
Your assistance will be appreciated. I had this down pat for a long time and all browsers would work. IE7 is using the old xsl and displays all nodes in text but does not do the transformation I am working on here. I hope to get this project, once again, available to all (or most) browsers.
I knew that your input had placed me near the goal. I ran trials until I settled for this xslt:
code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:regex="http://exslt.org/regular-expressions"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:param name="filter" select="'EWR'"/>
<xsl:template match="/">
<html>
<head>
<title>Special Airline Fares List</title>
</head>
<body>
<h1>Special Fares List</h1>
<xsl:for-each select="XML/item">
<xsl:if test="contains(description, $filter)">
<xsl:call-template name="q" />
</xsl:if>
</xsl:for-each>
</body>
</html>
</xsl:template>
<xsl:template name="q" match="item">
<p>
<xsl:apply-templates select="pubDate"/>
<xsl:apply-templates select="title"/>
<xsl:apply-templates select="link"/>
<xsl:apply-templates select="description"/>
</p>
</xsl:template>
<xsl:template match="pubDate">
<br /><span style="color:#991111">
<xsl:value-of select="." />
</span><br />
</xsl:template>
<xsl:template match="title">
<span style="color:#2A7B39">
<xsl:value-of select="." />
</span><br />
</xsl:template>
<xsl:template match="link">
<span style="color:#636763">
<a href="{.}">
<xsl:value-of select="." />
</a>
</span><br />
</xsl:template>
<xsl:template match="description">
<span style="color:#111111">
<xsl:value-of select="." />
</span><br /><br />
</xsl:template>
</xsl:transform>
which does precisely what people need it to do. Now I can move to the next hair pulling, forehead slapping project: passing the param in from a form.
Again, George, thank you.
Steve
Hello;
I am teaching myself to capture a form variable and pass it via param to xslt where form input will filter an xml database and transform the results for display on the xhtml document. It seems my task is complicated because I do not want to return just the node text but all of the child nodes text so the user can have the information and link to proceed further.
Here is a snippet from the xml:
code:
<item>
<pubDate>Tue, 20 Jan 2009 14:12:00 UT</pubDate>
<title>Air France Airlines DE Specials 90120</title>
<link>http://airtravelcenter.com/aff/air-fran ... .htm</link>
<description>PREIS IM EUR, Hin und Ruckflug inkl Steuern Gebuhren, Buchungszeitraum ab sofort bis 17 Feb, Preise ab nach Hamburg: Sao Paolo 595, Rio de Janeiro 640, Caracas 590, Mexiko City 589, Buenos Aires 877, Bogota 650, Santiago de Chile 927, Havanna 488, Saint Martin 721, Peking 491, Shanghai 491, Hongkong 605, Seoul 535, Singapur 527, Tokio 674, Osaka 634, Nagoya 693, Mumbai 502, Delhi 502, Chennai 522, Bangalore 519, Antananarivo 998, Dubai 452, Amman 475.</description>
</item>
<item>
<pubDate>Tue, 03 Feb 2009 12:18:00 UT</pubDate>
<title>Air France Airlines SE Specials 90203</title>
<link>http://airtravelcenter.com/aff/air-fran ... .htm</link>
<description>Prices in SEK, Return Flights, Tax Included, BOOK BY 16 Feb, Depart Stockholm TO: Paris 1 395, Nice 1 695, Toulouse 2 295, Rome 1 695, Madrid 1 695, Barcelona 1 695, Geneva 1 695, Malaga 1 695, New York 3 670, Chicago 4 155, Miami 4 630, Los Angeles 5 030, Mexico City 6 565, Bogota 8 300, Buenos Aires 8 065, Caracas 7 400, Sao Paulo 6 270, Rio de Janeiro 6 370, Beijing 4 480, Shanghai 4 830, Hong Kong 6 000, Tokyo 6 405, Hanoi 8 290, Cairo 4 380, Dubai 4 640, Beirut 5 290, Johannesburg 6 375, Dakar 8 420, Mauritius 7 815, Santo Domingo 7 860, Havana 7 875, Seychelles 8 285, Saint Marteen 8 440.</description>
</item>
and here is the xslt:
code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:regex="http://exslt.org/regular-expressions"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:template match="XML">
<html>
<head>
<title>Special Airline Fares List</title>
</head>
<body>
<h1>Special Fares List</h1>
<xsl:apply-templates/>
</body>
</html>
<xsl:call-template name="query"/>
</xsl:template>
<xsl:template name="query" match="query">
<xsl:for-each select="XML/item/*">
For now, I am just trying to type in what would be passed in from the form, just to get my brain wrapped around this part. I will tackle the javascript portion once I have this filter working.
<xsl:choose>
<xsl:when test="???">
<xsl:call-template name="q"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>EWR not found</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
<xsl:template name="q" match="item">
<p>
<xsl:apply-templates select="pubDate"/>
<xsl:apply-templates select="title"/>
<xsl:apply-templates select="link"/>
<xsl:apply-templates select="description"/>
</p>
</xsl:template>
<xsl:template match="pubDate">
<br /><span style="color:#991111">
<xsl:value-of select="." />
</span><br />
</xsl:template>
<xsl:template match="title">
<span style="color:#2A7B39">
<xsl:value-of select="." />
</span><br />
</xsl:template>
<xsl:template match="link">
<span style="color:#636763">
<a href="{.}">
<xsl:value-of select="." />
</a>
</span><br />
</xsl:template>
<xsl:template match="description">
<span style="color:#111111">
<xsl:value-of select="." />
</span><br /><br />
</xsl:template>
</xsl:transform>
Your assistance will be appreciated. I had this down pat for a long time and all browsers would work. IE7 is using the old xsl and displays all nodes in text but does not do the transformation I am working on here. I hope to get this project, once again, available to all (or most) browsers.