Request 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>
Target XML: Must only consider the schools with name containing "Wisconsin" but name should not contain "Academy". So it will just return the below:
<SchoolName>
<name>ABC International, Wisconsin</name>
<rank>1</rank>
</SchoolName>
Whats the best way to achieve this? How should the XSLT file for achieving this look like?
You can achieve your goal with either xslt:if
filter
<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>
or select predicate:
<xsl:for-each select="SchoolNames/SchoolName[name[contains(text(),'Wisconsin')] and not(name[contains(text(),'Academy')])]">
<!-- do something -->
</xsl:for-each>