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 17th, 2009, 01:07 PM
Authorized User
 
Join Date: Feb 2009
Posts: 43
Thanks: 10
Thanked 0 Times in 0 Posts
Default Display rows based on a parameter

This is in xslt 1.0

I have the following xsl.



Code:
<xsl:variable name="numPr" select="$dcrl/pressreleasestoreturn" />
<xsl:for-each select="$dcr">
                    <xsl:sort order="descending" select="concat(substring(date,7,4), substring(date,1,2), substring(date,4,2))"/>
                    <xsl:variable name="numtext" select="$dcrl/textreturnsize"/>
                    <xsl:choose>
                      <xsl:when test="$numtext != ''">
                        <a href="$PAGE_LINK[/press-releases/detail]dcr={@dcr}"><xsl:value-of select="substring(title,1,$numtext)"/></a><br/>
                      </xsl:when>
                      <xsl:otherwise>
                        <a href="$PAGE_LINK[/press-releases/detail]dcr={@dcr}"><xsl:value-of select="title"/></a><br/>
                      </xsl:otherwise>
                    </xsl:choose>  
                  </xsl:for-each>
I need to display a number of rows based on the value of $numPr.

How do I limit the number of rows displayed, after the rows have been sorted by date - I need to display the latest articles, based on $numPr.


My xml is below....

Code:
<Properties>
   -   <Data>
   -     <Result >
   -       <Externals>  
     <PressRelease>
                   <date>10/02/08</date> 

                <title>Media Centre PR</title>                

        </PressRelease>





-       </Externals>
 
      </Result>
   -   </Data>
</Properties>
Thanks
 
Old March 17th, 2009, 01:50 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

It is not clear what kind of rows you are referring to as neither the XML nor the stylesheet has any 'row' elements (or XHTML 'tr' elements for instance).
If you have an
Code:
<xsl:for-each select="foo">
  <xsl:sort select="bar"/>
and you want to output only the first $numPr elements in sort order then you can use e.g.
Code:
<xsl:for-each select="foo">
   <xsl:sort select="bar"/>
   <xsl:if test="position() &lt;= $numPr">
      <!-- now output stuff here e.g. -->
      <xsl:copy-of select="."/>
   </xsl:if>
</xsl:for-each>
Does that help? If not then please provide a relevant but minimal well-formed XML sample and the corresponding XML or HTML transformation result you want to create with your stylesheet.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
The Following User Says Thank You to Martin Honnen For This Useful Post:
rabs (March 17th, 2009)
 
Old March 17th, 2009, 02:21 PM
Authorized User
 
Join Date: Feb 2009
Posts: 43
Thanks: 10
Thanked 0 Times in 0 Posts
Default

Thanks Martin - that worked.





Similar Threads
Thread Thread Starter Forum Replies Last Post
can I filter rows based on this type of constraint callagga SQL Language 2 August 21st, 2008 04:31 PM
Default Rows Based Upon Number of XML Attributes. Mr.T Infopath 0 November 5th, 2007 07:29 PM
based upon parameter perform action warsha_14 Struts 4 August 5th, 2006 04:51 AM
select rows based on a criteria and paste ashu_gupta75 Excel VBA 2 July 30th, 2004 01:32 AM





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