How can I use the current object in a loop as part of a query?
Hi,
I have an XML document with 2 parts, meta data and data.
In the data part I have a list of word elements and each word element has several test elements indicating tests that were done of this word and the results of these tests (each test has a separate test element which is a sub element of word). each test element has a passed attribute with a Boolean value
In the metadata part I have a list of all the tests that were conducted in general (on all the words).
I want to loop around the tests in the metadata part and for each test I want to count the words that have this test as a subelement with a True value to the passed attribute. I couldn't find any way to do this.
what I'm trying to basically do is to use the name of the test in the current part of the loop as part of a separate XPath query?
Here is an example of the XML document:
<?xml version="1.0" encoding="ISO-8859-1"?>
<compare>
<info>
<list type="tests">
<item type="test" name="firstequal">Test whether the supersense with the highest rank is identical</item>
<item type="test" name="hresholdnonordered">Test whether the group of highest ranked supersenses is identical, not checking whether the order is identical</item>
<item type="test" name="hresholdordered">Test whether the group of highest ranked supersenses is identical, not checking whether the order is identical</item>
</list>
</info>
<comparison>
<word lemma="shot">
<test name="firstequal" passed="False">
<sense type="semcor" rank="1">noun.act</sense>
</test>
<test threshold="0.8" name="hresholdnonordered" passed="True">
<sense type="semcor" rank="1" sense="noun.act">1.0</sense>
</test>
<test threshold="0.8" name="hresholdordered" passed="False">
<sense type="semcor" rank="1" sense="noun.act">1.0</sense>
</test>
</word>
<word lemma="office">
<test name="firstequal" passed="False">
<sense type="semcor" rank="1">noun.group</sense>
</test>
<test threshold="0.8" name="hresholdnonordered" passed="True"> <sense type="semcor" rank="1" sense="noun.group">1.0</sense>
</test>
<test threshold="0.8" name="hresholdordered" passed="False">
<sense type="semcor" rank="1" sense="noun.group">1.0</sense>
</test>
</word>
</comparison>
<compare>
And this is an example of an XSLT code I was trying to use but it doesn't work (I hope that reading it will give better insight to what I was trying to achieve):
<xsl:for-each select="compare/info/list[@type='tests']/item">
<xsl:variable name="tname" select="@name" />
<xsl:value-of select="translate('count(/compare/comparison/word/test[@name="%s" and @passed="True"]/parent::node()/@lemma)','%s'$tname"/>
</xsl:for-each>
Anyone has an idea how I may use the name of the test in the current part of the loop as part of a separate XPath query?
Thanks for any help :)
|