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 31st, 2018, 05:47 PM
Authorized User
 
Join Date: Apr 2010
Posts: 61
Thanks: 12
Thanked 0 Times in 0 Posts
Default Limit Returned Results in for-each Loop

Hello.

I have the following XML code.
Code:
<doc>
  <EOB>
    <DETAIL>
      <DETAILLINE>
         <CRCDATA>
           <CRCDATALINE>
             <CRC>LINE1CRC1</CRC>
             <CRCFUNCTION>700</CRCFUNCTION>
           </CRCDATALINE>
           <CRCDATALINE>
             <CRC>LINE1CRC2</CRC>
             <CRCFUNCTION>900</CRCFUNCTION>
           </CRCDATALINE>
        </CRCDATA> 
      </DETAILLINE>
      <DETAILLINE>
         <CRCDATA>
           <CRCDATALINE>
             <CRC>LINE2CRC3</CRC>
             <CRCFUNCTION>700</CRCFUNCTION>
           </CRCDATALINE>
           <CRCDATALINE>
             <CRC>LINE2CRC4</CRC>
             <CRCFUNCTION>700</CRCFUNCTION>
           </CRCDATALINE>
        </CRCDATA> 
      </DETAILLINE>
    </DETAIL>
  </EOB>
</doc/
I have the following "for-each" loop where I need to check the <CRC> and
<CRCFUNCTION> for each SEPARATE <DETAILLINE> as it goes through the loop. I have a variable that I need to set to "Y" if <CRC> has a value and it's
corresponding <CRCFUNCTION> has a value of 900 in any of the associated <CRCDATALINE> for a specific <DETAILLINE>.
Using the code below, my variable is always being set to "Y" for both the first <DETAILLINE> and the second <DETAILLINE>.
The variable should be "Y" for the first DETAILLINE and "N" for the second
<DETAILLINE>.

Code:
  <xsl:for-each select="DETAILLINE">
    <xsl:variable name="varDenialCRC">
      <xsl:choose>
        <xsl:when test="CRCDATA/CRCDATALINE/CRCFUNCTION[.='900'] 
                         and ../../CRCDATA/CRCDATALINE/CRC[.!='']">
          Y
        </xsl:when>
        <xsl:otherwise>
          N
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
  </xsl:for-each>
Any help with this will be greatly appreciated!

Thanks,
Rita
 
Old January 31st, 2018, 06:30 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

"I have a variable that I need to set to "Y" if <CRC> has a value and it's
corresponding <CRCFUNCTION> has a value of 900 in any of the associated <CRCDATALINE> for a specific <DETAILLINE>."

The part of the requirement that's not reflected in your code is the words "corresponding" and "associated". I'm not 100% sure I've interpreted your requirement correctly, but I would think the correct condition is

Code:
test="CRCDATA/CRCDATALINE[CRCFUNCTION='900' and CRC!='']"
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
ritagr (January 31st, 2018)
 
Old January 31st, 2018, 07:06 PM
Authorized User
 
Join Date: Apr 2010
Posts: 61
Thanks: 12
Thanked 0 Times in 0 Posts
Default Limit Returned Results in for-each Loop

That worked for me!
Thank you so much.





Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP loop through database and limit number of entries gilbertsavier Beginning PHP 0 July 31st, 2009 06:42 AM
recordsource conditioned on multible parameter queries-action if no results returned BabaYaga Access VBA 9 May 13th, 2009 09:49 AM
weird results with for-in loop threealligator Javascript How-To 1 August 7th, 2005 12:16 PM
Limit rows returned and next rows minhpx General .NET 1 August 12th, 2004 06:25 AM
limit rows returned in a list box stoneman Access 1 January 16th, 2004 10:46 PM





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