我的XML文档包含一系列不同类型的图书元素(小说、非小说等)。
我希望创建一个输出true的XSLT模板,如果:
我希望模板输出false,如果:
我下面的模板做了这个工作,但我希望你能提供一个更有效的解决方案。我的模板需要很多步骤来解决这样一个简单的问题。我怀疑我的模板在大量数据中的性能会很差。你能为这个问题提供一个超级有效的解决方案吗?
这是我的模板:
<xsl:template match="Books">
<xsl:variable name="fiction-books" select="Book[Genre eq 'Fiction']" />
<xsl:variable name="no-fiction-books-that-cost-more-than-10-dollars" select="not(exists(Book[Genre eq 'Fiction'][number(Cost) gt 10.00]))" />
<xsl:variable name="no-fiction-books" select="not(exists($fiction-books))" />
<xsl:value-of select="$no-fiction-books or $no-fiction-books-that-cost-more-than-10-dollars" />
</xsl:template>下面是一个示例输入( XSLT应该与此输入一起输出false ):
<Books>
<Book>
<Title>ABC</Title>
<Genre>Fiction</Genre>
<Cost>10.00</Cost>
</Book>
<Book>
<Title>DEF</Title>
<Genre>Fiction</Genre>
<Cost>20.00</Cost>
</Book>
</Books>发布于 2015-01-07 13:03:23
如果以下情况,我希望模板输出false:
不如:
<xsl:template match="/Books">
<xsl:value-of select="not(Book[Genre='Fiction']/Cost >10)" />
</xsl:template>注意,输出不是XML。
发布于 2015-01-07 15:43:32
您可以简单地使用
<xsl:value-of select="count(Book[Genre='Fiction'][Cost > 10]) = 0" />
这包括所有Genre是‘虚构’和Cost大于'10'的书。然后检查该计数是否等于0。
https://stackoverflow.com/questions/27820004
复制相似问题