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 March 25th, 2008, 06:44 AM
Authorized User
 
Join Date: Feb 2008
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem while using position() in for-loop


When i try to use position() inside the for-loop, i get only one record.It should display nine records.I tried removing the position() code and it displays 9 records.


<xsl:for-each select="$distinctPrepackIndicatorUpcCode">
        <xsl:call-template name="printPrepackBox">
            <xsl:with-param name="prepackItem" select="VariableDataSet/VariableDataElement[@Code='750']/@Value" />
            <xsl:with-param name="prePackUpc" select="VariableDataSet/VariableDataElement[@Code='790']/@Value" />
            <xsl:with-param name="totalPacks" select="./@Case1Count" />
        </xsl:call-template>
        <table width="94%" cellpadding="0" cellspacing="0" class="prepack_line_item_table" border = "1">
            <xsl:call-template name="printPrepackLineItemHeader"/>
<xsl:choose>
  <xsl:when test="$prepackItemIndex &lt;= count(key('prepackIndicatorUpcCodeKey', concat(VariableDataSet/VariableDataElement[@Code = '750']/@Value, '-', VariableDataSet/VariableDataElement[@Code = '790']/@Value)))">
<xsl:for-each select="key('prepackIndicatorUpcCodeKey', concat(VariableDataSet/VariableDataElement[@Code = '750']/@Value, '-', VariableDataSet/VariableDataElement[@Code = '790']/@Value))">
<xsl:if test="position() = $prepackItemIndex">
                                <xsl:call-template name="printPrepackLineItemRow">
                                    <xsl:with-param name="itemNo" select="./@Style" />
                                    <xsl:with-param name="itemColor" select="./@Color" />
                                    <xsl:with-param name="itemSize" select="./@Size" />
                                    <xsl:with-param name="itemUpc" select="./@UPC" />
                                    <xsl:with-param name="itemMsrp" select="VariableDataSet/VariableDataElement[@Code='620']/@Value" />
                                    <xsl:with-param name="qtyPerPack" select="./@Case1ItemQuantity" />
                                    <xsl:with-param name="totalUnits" select="./@Case1Count * ./@Case1ItemQuantity" />
                                </xsl:call-template>

    </xsl:if>
</xsl:for-each>
</xsl:when>
</xsl:choose>
</table>
</xsl:for-each>


 
Old March 25th, 2008, 06:48 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Well assuming that $prepackItemIndex is a number then position() appears to be working just fine - its only displaying the n'th record where $prepackItemIndex = n.

What where you expecting position() to do exactly?

/- Sam Judson : Wrox Technical Editor -/
 
Old March 25th, 2008, 06:58 AM
Authorized User
 
Join Date: Feb 2008
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Actually the count(key('prepackIndicatorUpcCodeKey', concat(VariableDataSet/VariableDataElement[@Code = '750']/@Value, '-', VariableDataSet/VariableDataElement[@Code = '790']/@Value)) returns 9 records.

I want to do a for-each on those 9 records and display to user in the report.$PrepackIndex will be 1 by default and i want to loop till 9.

 
Old March 25th, 2008, 07:01 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Right - so remove the <xsl:if> then. I don't see what the problem is.

position() returns the current position in the for-each loop, i.e. for the first item it returns 1, for the second it return 2 etc. So if you put a <xsl:if> in there based on position() it will only output the one item where the position matches the value of $prepackItemIndex.

/- Sam Judson : Wrox Technical Editor -/
 
Old March 25th, 2008, 07:08 AM
Authorized User
 
Join Date: Feb 2008
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks.I did not notice that checking.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Have a problem in For-each loop LeoMathew XSLT 2 July 16th, 2008 05:20 AM
Position() Method Problem kwilliams XSLT 3 May 20th, 2008 02:11 PM
Customised list - Image position problem terra CSS Cascading Style Sheets 6 September 1st, 2005 01:28 PM
while loop problem shoakat Classic ASP Databases 1 September 21st, 2004 03:44 PM





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