Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 7th, 2009, 02:41 AM
Registered User
 
Join Date: Jan 2009
Posts: 8
Thanks: 1
Thanked 2 Times in 1 Post
Default 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=&quot;%s&quot; and @passed=&quot;True&quot;]/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 :)
 
Old January 7th, 2009, 04:05 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I think the following does what you want. If not post an example of the desired output.
Code:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:template match="/">
<results>
<xsl:for-each select="compare/info/list[@type = 'tests']/item">
<test><xsl:value-of select="@name"/></test>
<wordCount>
<xsl:value-of select="count(/compare/comparison/word[test[@passed = 'True' and @name = current()/@name]])"/>
</wordCount>
</xsl:for-each>
</results> 
</xsl:template>
</xsl:stylesheet>
__________________
Joe
http://joe.fawcett.name/
The Following User Says Thank You to joefawcett For This Useful Post:
pagis (January 7th, 2009)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing previous item in current-group() in loop mikeymikey XSLT 1 January 4th, 2008 06:47 AM
Help with efficient coding (part of Dynamic Query miamikk SQL Language 1 July 17th, 2007 05:32 AM
Append Query to current active records markizan Access 2 September 26th, 2006 08:33 AM
Nested Query with an iif statment part 2 Corey Access 1 October 17th, 2005 12:47 PM
A query to extract part of a string RayL Access 3 March 10th, 2004 09:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.