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 April 28th, 2008, 07:13 PM
Registered User
 
Join Date: Apr 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Tricky conditional selection

Sorry for the bad title, I don't really know what to classify the problem as.

A snippet of my XML showing structure:
Code:
<Transactions>
  <Transaction>
    <FundTransaction>
      <tsmf_fund><fund_id>1</fund_id></tsmf_fund>
      <!--data I need->
    </FundTransaction>
    <FundTransaction>
      <tsmf_fund><fund_id>2</fund_id></tsmf_fund>

    </FundTransaction>
  </Transaction>
  <Transaction>
    <FundTransaction>
      <tsmf_fund><fund_id>1</fund_id></tsmf_fund>

    </FundTransaction>
  </Transaction>
</Transactions>
<StaticData>
  <tsmf_fund>
    <fund_id>1</fund_id>
  </tsmf_fund>
  <tsmf_fund>
    <fund_id>2</fund_id>
  </tsmf_fund>
  <tsmf_fund>
    <fund_id>3</fund_id>
  </tsmf_fund>
</StaticData>
Basically I want up to three (in this case only) iterations of a loop, one for each node "tsmf_fund" in //StaticData. Up to three because I only want to do the loop iteration if the fund_id is actually used somewhere in //Transactions. In this example I don't want the iteration of the loop for fund_id = 3 because it is not used.


This is what i've tried so far, all not returning any results.
Code:
<xsl:for-each select="//StaticData/tsmf_fund[count(//Transaction/FundTransaction[tsmf_fund/fund_id = current()/fund_id]) &gt; 0]">
<xsl:for-each select="//StaticData/tsmf_fund[//Transaction/FundTransaction[tsmf_fund/fund_id = current()/fund_id]]">
<xsl:for-each select="//StaticData/tsmf_fund[//Transaction/FundTransaction/tsmf_fund/fund_id = current()/fund_id]">
<xsl:for-each select="//StaticData/tsmf_fund[//FundTransaction/tsmf_fund/fund_id = current()/fund_id]">
<xsl:for-each select="//StaticData/tsmf_fund[//FundTransaction/[tsmf_fund/fund_id = current()/fund_id]]">

More specifically, the condition is: there exists a node "Transaction" in //Transactions/ which contains a node "FundTransaction" which has /tsmf_fund/fund_id equal to the fund_id in the iteration of the //StaticData loop.
 
Old April 28th, 2008, 07:40 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

<xsl:for-each select="//StaticData/tsmf_fund[count(//Transaction/FundTransaction[tsmf_fund/fund_id = current()/fund_id]) &gt; 0]">

The meaning of this depends crucially on what current() is, which you haven't told us. I can't see any possible value of current() in which this expression would make sense. The same applies to your other attempts. To select the find_id elements in StaticData that match one in Transactions, try

<xsl:variable name="tf" select="//Transactions//fund_id"/>

then

//StaticData/tsmf_fund[fund_id = $tf]

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 28th, 2008, 08:14 PM
Registered User
 
Join Date: Apr 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, my understanding of current() was incorrect. current() returns the root node and so the expression "current()/fund_id" equals "//fund_id" and so will always return false.
My intention, however, was for current() to return the //StaticData/tsmf_fund node that the function is testing in the for-each loop.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Tricky Queries balesh.mind SQL Server 2005 5 April 12th, 2008 10:29 PM
A tricky question mike_remember ASP.NET 1.0 and 1.1 Professional 3 October 27th, 2006 08:17 AM
Tricky Query BSkelding MySQL 5 August 31st, 2005 08:59 AM
Alright, here's a tricky one... Anubis Access VBA 14 November 19th, 2003 04:22 PM
Tricky SQL fastcorvette Access 2 October 10th, 2003 10:28 AM





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