在 XSLT 中,多对多属性在 for-each 条件下进行比较 [英] In XSLT, many to many attributes comparing in for-each condition
问题描述
使用 XSLT 1.0
Using XSLT 1.0
是否可以过滤多对多属性,我的意思是如下示例:../../../../fieldmap/field[@name"即超过1个元素作为包含field/@name"属性的fieldmap存在并且它与定义/@title进行比较,还有更多那么存在一个包含@title 的定义元素.
Is it possible to filter many to many attributes, i mean as below example: "../../../../fieldmap/field[@name" i.e. more then 1 elements as fieldmap containing "field/@name" attribute are exists and it is comparing with definition/@title and there too more then one definition element exists containing @title.
示例:
<xsl:for-each select="../../../../fieldmaps/field[@name=../destination/@title]">
您能否建议我如何实现——如果包含@name 的字段存在于任何定义/@title 中,那么只有那些记录应该在 for-each 循环中处理?(现在看起来,它只会与第一个@title 属性进行比较并考虑所有 fieldmaps/field/@name 属性)
Can you please suggest me how it could possible to achieve -- if field containing @name existed in any of defination/@title then only those records should be process within for-each loop? (as now, it looks, it will just compare with first @title attribute and consider all fieldmaps/field/@name attributes)
谢谢
推荐答案
您可以使用变量来实现:
You can achieve that using a variable:
<xsl:variable name="titles" select="../destination/@title"/>
<!--now "titles" contains a nodeset with all the titles -->
<xsl:for-each select="../../../../fieldmaps/field[@name=$titles]">
<!-- you process each field with a name contained inside the titles nodeset -->
</xsl:for-each>
这里有一个简化的例子:
Here you have a simplified example:
输入:
<parent>
<fieldmaps>
<field name="One"/>
<field name="Two"/>
<field name="Three"/>
</fieldmaps>
<destinations>
<destination title="One"/>
<destination title="Two"/>
</destinations>
</parent>
模板:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- ++++++++++++++++++++++++++++++++ -->
<xsl:template match="parent">
<Results>
<xsl:variable name="titles" select="destinations/destination/@title"/>
<xsl:for-each select="fieldmaps/field[@name=$titles]">
<Result title="{@name}"/>
</xsl:for-each>
</Results>
</xsl:template>
<!-- ++++++++++++++++++++++++++++++++ -->
</xsl:stylesheet>
输出:
<Results>
<Result title="One"/>
<Result title="Two"/>
</Results>
我希望这会有所帮助!
这篇关于在 XSLT 中,多对多属性在 for-each 条件下进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!