I am sure it is simple, but I just do not see a tree for trees.
I have an XML that looks like this:
<root> <profil> <e1 a="2">1</e1> <m1 a="3">1</m1> <e2 a="4">1</e2> <m2 a="5">1</m2> </profil> <profil> <e1 a="5">1</e1> <m1 a="3">1</m1> <e2 a="4">1</e2> <m2 a="4">1</m2> </profil> <profil> <e1 a="7">1</e1> <m1 a="7">1</m1> <e2 a="4">1</e2> <m2 a="2">1</m2> </profil> </root>
Now I want to know how much / m * / @ a is equal to e * / @ a per / profil. So I came up with the following XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="*"> <xsl:element name="root"> <xsl:for-each select="/root/profil"> <xsl:element name="count"> <xsl:value-of select="count(*[contains(name(), 'm') and ./@a = //*[contains(name(),'e')]/@a])"/> </xsl:element> </xsl:for-each> </xsl:element> </xsl:template> </xsl:stylesheet>
But the result is incorrect:
<root> <count>1</count> <count>1</count> <count>2</count> </root>
It should be
<root> <count>0</count> <count>1</count> <count>1</count> </root>
Does anyone have a suggestion what am I doing wrong?
Sdudda
source share