使用变量选择元素

Ros*_*son 4 xml xslt fxsl

基本上我有一个小模板,看起来像:

<xsl:template name="templt">
    <xsl:param name="filter" />
    <xsl:variable name="numOrders" select="count(ORDERS/ORDER[$filter])" />
</xsl:template>
Run Code Online (Sandbox Code Playgroud)

我正试着用它来调用它

<xsl:call-template name="templt">
    <xsl:with-param name="filter" select="PRICE &lt; 15" />
</xsl:call-template>
Run Code Online (Sandbox Code Playgroud)

不幸的是,似乎在调用模板之前对其进行评估(因此有效地传递了"false")将其括在引号中只会使它成为字符串文字,因此也不起作用.有人知道我想要实现的目标是否可行?如果是这样,你能否对它有所了解?干杯

Dir*_*mar 6

以下怎么样:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>

  <xsl:template name="templt">
    <xsl:param name="filterNodeName" />
    <xsl:param name="filterValue" />
    <xsl:variable name="orders" select="ORDERS/ORDER/child::*[name() = $filterNodeName and number(text()) &lt; $filterValue]" />
    <xsl:for-each select="$orders">
      <xsl:value-of select="."/>
    </xsl:for-each>
  </xsl:template>

  <xsl:template match="/">
    <xsl:call-template name="templt">
      <xsl:with-param name="filterNodeName" select="'PRICE'" />
      <xsl:with-param name="filterValue" select="15" />
    </xsl:call-template>
  </xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

如果您仍想仅使用单个参数,则可以先在模板'templt'中进行标记.