xsl 匹配或条件
xsl match or condition
我有一个 XML 文件,如下所示:
<bases>
<marker>
<name>whatever</name>
<city>Svetly</city>
<country>Kaliningrad</country>
</marker>
<marker>
<name>whatever</nane>
<city>Boston</city>
<country>US</country>
</marker>
<marker>
<name>whatever</nane>
<city>Moscow</city>
<country>Russia</country>
</marker>
</bases>
此 XSL 允许我进行选择性复制 - 在本例中国家/地区等于俄罗斯。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- Remove all marker elements where country not 'Russia' -->
<xsl:template match="marker[not(country='Russia')]"/>
<!-- Identity template -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
我想实现 OR 条件,例如 where country equals Russia OR Kaliningrad,但我无法理解语法。这不起作用:
在 XSLT 2 或 3 中:<xsl:template match="marker[not(country=('Russia', 'Kaliningrad'))]"/>
。在 XSLT 1 中:<xsl:template match="marker[not(country='Russia' or country = 'Kaliningrad')]"/>
我有一个 XML 文件,如下所示:
<bases>
<marker>
<name>whatever</name>
<city>Svetly</city>
<country>Kaliningrad</country>
</marker>
<marker>
<name>whatever</nane>
<city>Boston</city>
<country>US</country>
</marker>
<marker>
<name>whatever</nane>
<city>Moscow</city>
<country>Russia</country>
</marker>
</bases>
此 XSL 允许我进行选择性复制 - 在本例中国家/地区等于俄罗斯。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- Remove all marker elements where country not 'Russia' -->
<xsl:template match="marker[not(country='Russia')]"/>
<!-- Identity template -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
我想实现 OR 条件,例如 where country equals Russia OR Kaliningrad,但我无法理解语法。这不起作用:
在 XSLT 2 或 3 中:<xsl:template match="marker[not(country=('Russia', 'Kaliningrad'))]"/>
。在 XSLT 1 中:<xsl:template match="marker[not(country='Russia' or country = 'Kaliningrad')]"/>