xslt - 在XSLT中按范围限制输出

标签 xslt xpath xslt-2.0

我正在创建XSLT,并且仅当其子元素值之一在范围之间时,才想选择一个特定节点。该范围将使用xsl文件中的参数指定。

XML文件就像

<root>
 <org>
  <name>foo</name>
  <chief>100</chief>
 </org>
 <org parent="foo">
  <name>foo2</name>
  <chief>106</chief>
 </org>
</root>


到目前为止,XSLT是

<xsl:param name="fromRange">99</xsl:param>
<xsl:param name="toRange">105</xsl:param>

<xsl:template match="/">
    <xsl:element name="orgo">
        <xsl:apply-templates select="//org[not(@parent)]"/>
    </xsl:element>
</xsl:template>


我想限制正在处理其节点的值不在范围内的组织节点

最佳答案

我想选择一个特定的节点,
仅当其子元素的
值在一个范围之间。范围是
使用中的参数指定
xsl文件。

我也想要限制
节点不应具有paren t
属性和范围


将此表达式用作select<xsl:apply-templates>属性的值:

org[not(@parent) and chief >= $fromRange and not(chief > $toRange)]


在XSLT 2.0中,在匹配模式中包含变量/参数是合法的。

因此,可以这样写:

<xsl:template match=
  "org[@parent or not(chief >= $fromRange ) or chief > $toRange]"/>


因此有效地将所有这些org元素排除在处理之外。

然后,与文档节点匹配的模板就是:

<xsl:template match="/">            
    <orgo>            
        <xsl:apply-templates/>            
    </orgo>            
</xsl:template>


这比XSLT 1.0解决方案更好,因为它更“推式”。

关于xslt - 在XSLT中按范围限制输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3851621/

相关文章:

xslt - XPath表达式以选择不是某个特定元素的所有子元素

css - Oxygen XML 中的 XPath 和 CSS 作者 : How to create a dynamic parameter in oxy_xpath

javascript - jquery : create xpath of the current text selection

position - 在 xpath 表达式中引用当前节点的位置

XSLT 拆分输出文件 - muenchian 分组

XSLT nowrap 和 XHTML 1.0 Strict

xslt - xslt中的动态xpath?

java - 如何在Selenium RC中使用按钮的Xpath?

xml - 使用 for-each-group 进行 XSLT 嵌套分组

xml - 使用 XSLT 将数字四舍五入到最低百位