[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

counting elements with values that match other element

Subject: counting elements with values that match other element values
From: Sean Whalen <seanwhalen@xxxxxxxxxxx>
Date: Thu, 18 May 2006 07:28:17 -0400
elements and values
I step away from xpath and xslt for long stretches, and when I come back, parts of the big picture are a little fuzzy. My sense is that for the problem below, I need to loop; the test can't be done in a single XSLT1.0 statement. I have a set of elements ("t") with children under them ("t/cSet/c"). I'm looking for children that occur twice. I'd like get a nice 1.0 nodeset, which is the practical reason for trying to shoehorn the task into a single statement.

The xslt and xml are below. I used command-line saxon for debugging.

The expression for the element "Find_Cs_In_Ts" is what I'd like to either get working, or get an official confirmation that the task is impossible. In the real implementation the "&gt; 0" would be " = 2", and the answer would be "3, 5, and 7", which are the numbers that occurs twice in the set. The other elements are just me playing around with similar constructions that return related data.

In SQL, this would be something like
select * from ccc where (select count (*) from T/cSet as TC where tc.c = ccc.c ) >0


Any explanation for what the right syntax is, or, conceptually, why the idea doesn't fit in with xslt1.0 would be greatly appreciated. I've got looping code for the task almost implemented, so, mostly I'm asking for how the parser is reading the expression I wrote, and how far away is what I wrote from what I really wanted?

Another approach might be to use the parent axis to walk back up and then over to other T elements to find the related data.

thanks for any suggestions,


======================
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema">


<xsl:output method="html"/>

<xsl:template match="/">
<xsl:call-template name="make-Choices">
</xsl:call-template>


</xsl:template>

<xsl:template name = "make-Choices">

<xsl:variable name = "output" >
<xsl:element name="root">
<xsl:element name = "ccc"><xsl:copy-of select="root/ccc/*"/> </xsl:element>


<xsl:element name = "Find_Cs_In_Ts"><xsl:copy-of select="
//root/ccc/c[ count( //root/t[ h =1 and . = cSet/c ] ) &gt; 0 ] "/> </xsl:element>



<xsl:element name = "Count7s_In_TH"><xsl:copy-of select="
count( //root/t[ h =1 and cSet/c = 7 ] ) "/> </xsl:element>


<xsl:element name = "Cs_In_Ts"><xsl:copy-of select="
//root/ccc/c[ . = //root/t[ h =1 ]/cSet/c ] "/> </xsl:element>



<xsl:element name = "Count_TCs_In_C"><xsl:copy-of select="count( root/t[h =1]/cSet/c[. = //root/ccc/c] ) "/> </xsl:element> </xsl:element> </xsl:variable>


<xsl:copy-of select="$output"/>

</xsl:template>


</xsl:stylesheet>


============
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="ukbSmall.xslt"?>
<root>
<ccc>
<c>1</c><c>2</c><c>3</c><c>4</c><c>5</c><c>6</c><c>7</c><c>8</c><c>9</c>
</ccc>
<t>
<h>1</h><v>3</v>
<cSet><c>3</c><c>5</c><c>8</c></cSet>
</t> <t>
<h>1</h><v>4</v>
<cSet><c>3</c><c>5</c></cSet>
</t>
<t>
<h>1</h><v>7</v>
<cSet><c>7</c><c>8</c></cSet>
</t>
<t>
<h>1</h><v>9</v>
<cSet><c>7</c><c>8</c></cSet>
</t> </root>


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.