使用Saxon-ce通过组合框显示滤波输出

时间:2013-08-30 18:33:19

标签: xslt-2.0 saxon

我正在尝试使用Saxon-ce设置一个组合框,其值过滤xml中项目的显示。这是我到目前为止的代码示例。

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:ext="http://exslt.org/common" 
xmlns:ixsl="http://saxonica.com/ns/interactiveXSLT"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
extension-element-prefixes="ixsl">

<xsl:template match="/">
    <!-- set up combo box -->
<xsl:result-document href="#typeControl">
    <xsl:text>Type: </xsl:text>
    <select class="menuSub_monster" id="typeBox">
        <option value="all" selected="'all'">Unsorted</option>
        <option value="group">Sorted</option>
        <option value="value1">Value1</option>
        <option value="value2">Value2</option>
    </select>
</xsl:result-document>

<!-- inital display -->
<xsl:call-template name="displayTemplates">
    <xsl:with-param name="typeSel" select="'all'"/>
</xsl:call-template>
</xsl:template>

<!-- Change display when we change combo box -->
<xsl:template match="select[@id='typeBox']" mode="ixsl:onchange">
<xsl:variable name="control" select="."/>
<xsl:variable name="typeValue" select="ixsl:get($control,'value')" />   

<xsl:call-template name="displayTemplates">
    <xsl:with-param name="typeSel" select="$typeValue"/>
</xsl:call-template>
</xsl:template>

<!-- display routine -->
<xsl:template name="displayTemplates">
<xsl:param name="typeSel"/>
<xsl:result-document href="#display" method="ixsl:replace-content" >
<xsl:choose>
   <xsl:when test="$typeSel='all'">
    <xsl:for-each select="templates/template">
    <xsl:sort select="sort_name"/>
    ... CODE FOR DISPLAY
    </xsl:for-each>
   </xsl:when>
   <xsl:when test="$typeSel='group'">
    ... CODE FOR DISPLAY
   </xsl:when>
   <xsl:otherwise>
    <xsl:for-each select="templates/template/types[type[text()=$typeSel]]">
    <xsl:sort select="../sort_name"/>
            ...CODE FOR DISPLAY
    </xsl:for-each>
   </xsl:otherwise>
</xsl:choose>
</div>  

</xsl:result-document>
</xsl:template> 

我遇到的问题是当组合框改变值时调用模板displayTemplates。我转换到上下文模板/模板不起作用,因为这是我使用此样式表调用的XML的一部分。但是,match =“select [@ id ='typeBox']”将上下文设置为不在XML中的对象。如何将我的上下文从组合框更改为我的XML,以便显示例程中的for-each语句正常工作?

1 个答案:

答案 0 :(得分:0)

一种方法:将变量绑定到XML中的某个节点,您可以从中成功导航到需要的位置。然后使用对该变量的引用将上下文移回另一个文档。 (可能有更优雅的方式。)