1

I have defined a variable called tags which selects a node set of elements whose names are one of several values:

<xsl:variable name="tags" select="//xs:element[@name='Subscription' or @name='Account' or @name='Product'  or @name='ProductRatePlan' or @name='ProductRatePlanCharge' or @name='Usage']"/>

I would like to define a variable as such:

<xsl:variable name="tagNames" select="'Subscription','Account','Product','ProductRatePlan','ProductRatePlanCharge','Usage'/>

How could I rewrite the first expression to select all the nodes whose names are in the set $tagNames? In essence, I'm looking for an operation that is analagous to a SQL set membership:

SELECT * FROM tags WHERE name in ('Subscription', 'Account', 'Product'....)
4

2 回答 2

2

在 XPath 2.0 中,您可以编写:

<xsl:variable name="tags" select="//xs:element[@name=('Subscription','Account','Product','ProductRatePlan','ProductRatePlanCharge','Usage')]"/>
于 2013-04-08T21:00:26.683 回答
1

一种方法

//xs:element
  [contains('|Subscription|Account|Product|ProductRatePlan|ProductRatePlanCharge|Usage|',
            concat('|', @name, '|'))]

所以,你可以有一个变量或参数

<xsl:variable name="vTags"
 select="'|Subscription|Account|Product|ProductRatePlan|ProductRatePlanCharge|Usage|'"/>

并且您的主要 XPath 表达式变为

//xs:element[contains($vTags, concat('|', @name, '|'))]
于 2013-04-09T04:02:47.890 回答