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

Workaround for Sablotron param issue

Subject: Workaround for Sablotron param issue
From: Ted Stresen-Reuter <tedmasterweb@xxxxxxx>
Date: Tue, 4 Mar 2003 13:20:52 -0600
param name whatever value
Hi,

I'm trying to pass a param to a template as follows

<xsl:apply-templates select="option">
    <xsl:with-param name="selected" select="@value" />
</xsl:apply-templates>

<xsl:template match="option">
    <xsl:param name="selected" />
    <xsl:copy><xsl:value-of select="$selected" /></xsl:copy>
</xsl:template>

However, no output is sent to the result tree. I am using the Sablotron processor (inside PHP) and I am able to get a result using call-template (with-param), but this is not the ideal solution. Is this a missing feature in Sablotron (couldn't find the answer on their web site) or is it something I'm doing wrong in XSL?

Ted Stresen-Reuter

PS: the _real_ problem follows, but for those of you who aren't up for reading the whole thing, I'm including it here, after the main question...

Basically, I've got an XHTML document with a FORM element. I'm trying to get the POST data from a form submission (which I've converted into an XML format) into the value attributes of the FORM element. Yes, I'm trying to completely separate presentation from logic.

I'm trying to use the document() XPath function to walk through the POST data looking for fields whose names match the fields in the XHTML document. When I get to a SELECT element, though, I need to then get the OPTION elements and find the one whose value matches the text() node of the corresponding POST data element so that I can set its "selected" attribute to true (or "selected", as is the case with XHTML). (aside: I can hardly believe how hard it is to describe this...)

Unfortunately, it would appear that the Sablotron processor doesn't pass params when calling templates via apply-templates. Any suggestions for a workaround or am I just missing something???

XML Document
<html>
<head>
....
<select name="whatever">
<option value="one" label="First Choice">First Choice</option>
<option value="two" label="Second Choice"> Second Choice</option>
<option value="three" label="Third Choice"> Third Choice</option>
</select>
....
</html>


XSL Document

(... standard stuff )

<xsl:template match="select">
<xsl:for-each select="document($source)/row/col">
<!-- $source is a file consisting of one <rows> element followed by one <row> element with multiple <col> children elements where every <col> element is not empty -->
<xsl:if test="@name = $fieldName">
<xsl:choose>
<xsl:when test="$fieldType = 'select'">
<xsl:apply-templates select="option">
<xsl:with-param name="selected" select="text()" />
</xsl: apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="text()" />
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:for-each>
</xsl:template>


<xsl:template match="option">
    <xsl:param name="selected" />
    <xsl:if test="@value = $selected">
	<xsl:attribute name="selected">selected</xsl:attribute>
    <xsl:if>
</xsl:template>


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.