xslt通过多个列值选择tablerow
我得到了以下XML:xslt通过多个列值选择tablerow,xslt,search,multiple-columns,xmltable,Xslt,Search,Multiple Columns,Xmltable,我得到了以下XML: <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <row> <column> <name>COL_A</name>
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<row>
<column>
<name>COL_A</name>
<string>xxx</string>
</column>
<column>
<name>COL_B</name>
<currency>yyy</currency>
</column>
<column>
<name>COL_C</name>
<number>zzz</number>
</column>
</row>
<row>
<column>
<name>COL_A</name>
<string>aaa</string>
</column>
<column>
<name>COL_B</name>
<currency>bbb</currency>
</column>
<column>
<name>COL_C</name>
<number>ccc</number>
</column>
</row>
</soap:Body>
</soap:Envelope>
科鲁阿
xxx
科鲁布
yyy
科鲁克
zzz
科鲁阿
aaa
科鲁布
bbb
科鲁克
ccc
我想检测是否存在列/值三元组的行
(A列=aaa,B列=bbb,C列=ccc)
我写了这个xslt,但我只能匹配第一对,不知道如何继续
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:template match="Envelope">
<xsl:apply-templates select="/Body/row"/>
</xsl:template>
<xsl:template match="row">
<xsl:choose>
<xsl:when test="(column/name = 'COL_A') and (column/string = 'xxx' )">
<xsl:text> Found </xsl:text>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
建立
我编写该脚本是为了理解如何找到具有这些值(aaa、bbb、ccc)的行。
然后,如果可能的话,我需要一个xpath语句来检查是否存在具有这些值的行。您可以
和
-在xsl:when
中组合三个节点存在性测试。因此,要匹配第二行
column[name = 'COL_A' and string = 'aaa'] and column[name = 'COL_B' and currency = 'bbb'] and column[name = 'COL_C' and number = 'ccc']
此XPath-1.0表达式满足您的要求
以下是整个测试样式表:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<xsl:template match="/soap:Envelope">
<xsl:apply-templates select="soap:Body/row"/>
</xsl:template>
<xsl:template match="row">
<xsl:choose>
<xsl:when test="column[name = 'COL_A' and string = 'aaa'] and column[name = 'COL_B' and currency = 'bbb'] and column[name = 'COL_C' and number = 'ccc']">
<xsl:text> Found </xsl:text>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
建立