1
votes

I am making controls on a web page (comboboxes) with Saxon-CE and Xslt 2.0. I am having trouble in passing the values of multiple control to a template that uses the values from that control to process the document. Here is what I have:

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:ixsl="http://saxonica.com/ns/interactiveXSLT"
extension-element-prefixes="ixsl">

<xsl:template match="/">

<xsl:result-document href="#comboBox1">
  <select id="myBox1">
    <option value="1">One</option>
    <option value="2">two</option>
  </select>
</xsl:result-document>

<xsl:result-document href="#comboBox2">
  <select id="myBox2">
    <option value="A">Letter-A</option>
    <option value="B">Letter-B</option>
  </select>
</xsl:result-document>

</xsl:template>

<xsl:template match="select[@id='myBox1'] mode=ixsl:onchange">
 <xsl:variable name="control1" select="."/>
 <xsl:variable name="numVal" select="ixsl:get($control1,'value')"/>

 <xsl:call-template name="displayStuff">
   <xsl:with-param name="field1" select="$numVal"/>
 </xsl:call-template>
</xsl:template>

<xsl:template match="select[@id='myBox2'] mode=ixsl:onchange">
 <xsl:variable name="control2" select="."/>
 <xsl:variable name="letVal" select="ixsl:get($control2,'value')"/>

 <xsl:call-template name="displayStuff">
   <xsl:with-param name="field2" select="$letVal"/>
 </xsl:call-template>

</xsl:template>

<xsl:template name="displayStuff">
 <xsl:param name="field1" select="0"/>
 <xsl:param name="field2" select="Z">
  <xsl:result-document href="#display" method="ixsl:replace-content">
    <xsl:text>Number: </xsl:text> <xsl:value-of select="$field1"/><br/>
    <xsl:text>Letter: </xsl:text> <xsl:value-of select="$field2"/><br/>        
  </xsl:result-document>
</xsl:template>

</xsl:stylesheet>

The problem is that each control returns the correct value to the display template for an then item just changed, but not the other item.

For example if I select 1 in the first dropbox I get Number: 1 Letter: Z

but now if I change the vale of the second dropbox (for lets say to A) I get Number: 0 Letter:A.

How can I make sure what is passed to the display template is the current selected value of all the dropboxes, not the one just changed?

1

1 Answers

1
votes

Instead of passing the current values of the controls as parameters to the displayStuff template, why not have that template access them directly from the HTML page by means of XPath expressions?

I suspect you could combine all this into a single template:

<xsl:template match="select[@id=('myBox1', 'myBox2')] mode=ixsl:onchange">
 <xsl:variable name="control1" select="."/>
 <xsl:variable name="numVal" select="ixsl:get(id('myBox1'),'value')"/>
 <xsl:variable name="letVal" select="ixsl:get(id('myBox2'),'value')"/>
  <xsl:result-document href="#display" method="ixsl:replace-content">
    <xsl:text>Number: </xsl:text> <xsl:value-of select="$numVal"/><br/>
    <xsl:text>Letter: </xsl:text> <xsl:value-of select="$letVal"/><br/>        
  </xsl:result-document>
</xsl:template>