请求XML:
<SchoolName>
<name>ABC International, Wisconsin</name>
<rank>10</rank>
</SchoolName>
<SchoolName>
<name>XYZ Primary, Las Vegas</name>
<rank>4</rank>
</SchoolName>
<SchoolName>
<name>Ryan Academy, Wisconsin</name>
<rank>6</rank>
</SchoolName>
<SchoolName>
<name>Advanced Elementary, Houston</name>
<rank>15</rank>
</SchoolName>
目标XML: 必须只考虑名称中包含"Wisconsin"的学校,但名称中不能包含"Academy"。所以它会返回如下内容:
<SchoolName>
<name>ABC International, Wisconsin</name>
<rank>1</rank>
</SchoolName>
实现这一点的最好方法是什么?实现这一目标的XSLT文件应该是什么样的?
您可以使用xslt:if
过滤器
<xsl:for-each select="SchoolNames/SchoolName">
<xsl:if test="name[contains(text(),'Wisconsin')] and not(name[contains(text(),'Academy')])">
<!-- do something -->
</xsl:if>
</xsl:for-each>
或select predicate:
<xsl:for-each select="SchoolNames/SchoolName[name[contains(text(),'Wisconsin')] and not(name[contains(text(),'Academy')])]">
<!-- do something -->
</xsl:for-each>