【发布时间】:2021-02-26 14:16:21
【问题描述】:
我有这个 XML:
<table tableName="Groups">
<item table="Groups">
<column columnName="GroupID">GROUP1</column>
<column columnName="GroupID">GROUP2</column>
</item>
</table>
<table tableName="Products">
<item table="Products">
<column columnName="ProductID">1</column>
<column columnName="ProductName">Product A</column>
<column columnName="Groups">"GROUP1","GROUP2"</column>
</item>
<item table="EcomProducts">
<column columnName="ProductID">2</column>
<column columnName="ProductName">Product B</column>
<column columnName="Groups">"GROUP3","GROUP4"</column>
</item>
<item table="EcomProducts">
<column columnName="ProductID">3</column>
<column columnName="ProductName">Product C</column>
<column columnName="Groups">"GROUP1","GROUP3"</column>
</item>
</table>
我正在尝试过滤掉包含组表中存在的任何组的产品。 我想结束这个。
<products>
<product>
<name>Product A</name>
<groups>"GROUP1","GROUP2"</groups>
</product>
<product>
<name>Product C</name>
<groups>"GROUP1","GROUP3"</groups>
</product>
</products>
到目前为止,我有这个 XSLT,但由于我对 XSLT 还很陌生,我不知道如何使该测试语句更具动态性:
<products>
<xsl:for-each select="table[@tableName='Products']/item">
<xsl:if test="contains(column[@columnName = 'Groups'] = 'GROUP1' and contains(column[@columnName = 'Groups'] = 'GROUP2'">
<product>
<name><xsl:value-of select="column[@columnName = 'ProductName']"/></name>
<groups><xsl:value-of select="column[@columnName = 'Groups']"/></groups>
</product>
</xsl:if>
</xsl:for-each>
</products>
【问题讨论】:
-
那是哪个 XSLT 1.0 处理器?是否支持字符串函数来标记
"GROUP1","GROUP3"之类的值? -
您显示的输入不是格式正确的 XML:缺少根元素。