I just need to check if "pp" matches one of the motherβs cats attribute.
Good question, +1.
Easier than all the other answers :
/*/mother/@cat = 'pp'
This evaluates to true()
exactly when "pp"
is equal to the string value of the cat
attribute of the mother
element, which is a child of the top element of the XML document.
In this example, yes. But for "pr" this should be wrong.
Evaluate again :
/*/mother/@cat = 'pr'
The following is a simple conversion showing this in action :
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:template match="/"> /*/mother/@cat = 'pp' is <xsl:text/> <xsl:value-of select="/*/mother/@cat = 'pp'"/> /*/mother/@cat = 'pr' is <xsl:text/> <xsl:value-of select="/*/mother/@cat = 'pr'"/> </xsl:template> </xsl:stylesheet>
when applied to the provided XML document :
<rules> <mother cat="pp"> <daughter cat="pr"/> <daughter cat="np"/> </mother> <mother cat="wp"> <daughter cat="rp"/> <daughter cat="vp"/> </mother> <mother cat="cn"> <daughter cat="jj"/> <daughter cat="cn"/> </mother> <mother cat="np"> <daughter cat="jj"/> <daughter cat="np"/> </mother> </rules>
required, the correct result is obtained :
/*/mother/@cat = 'pp' is true /*/mother/@cat = 'pr' is false
source share