Solved

Can I control the display number of recrod in xsl?

Posted on 2001-08-15
14
263 Views
Last Modified: 2012-06-27
I use position()  but it didn't work! Who can tell me the way? Thank you!
0
Comment
Question by:hmfeng
  • 4
  • 4
  • 4
  • +2
14 Comments
 
LVL 2

Expert Comment

by:djokov
ID: 6391830
:-)) strange question..
Please post your not working code...
0
 

Author Comment

by:hmfeng
ID: 6392448
This the code I use:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/" >
<HTML>
<BODY>
<TABLE>
<xsl:for-each select="customers/customer[position()&gt;=1 and position()&lt;=10]" order-by="-phone;-name">
<TR>
<TD><xsl:value-of select="name"/></TD>    
<TD><xsl:value-of select="address"/></TD>
<TD><xsl:value-of select="phone"/></TD>
</TR>
</xsl:for-each>
</TABLE>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>


This is the error information in IE 5.0:
Unknown method. customers/customer[-->position()<-->=1 and position()<=10]
0
 
LVL 2

Expert Comment

by:djokov
ID: 6392837
First of all I thing the problem is that you use "order-by" in "for-each". I am sure that in XSL there is no such command. Try something like this:
i suppose your xml is something like:
<customers>
  <customer>
     <phone>11</phone>
     <name>Peter</name>
     <address>street</address>
  </customer>
</customers>
then:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/" >
<HTML>
<BODY>
<TABLE>
<xsl:for-each select="customers/customer">
<xsl:sort select="phone" data-type="number" order="ascending"/>
<xsl:sort select="phone" data-type="text" order="ascending"/>
<xsl:if test="position()>=1 and position()&lt;=10">
<TR>
<TD><xsl:value-of select="name"/></TD>    
<TD><xsl:value-of select="address"/></TD>
<TD><xsl:value-of select="phone"/></TD>
</TR>
</xsl:if>    
</xsl:for-each>
</TABLE>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>

Try it and let me know. In general i think that position will work in for-each also, but first try what i offer.

cheers
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 2

Expert Comment

by:djokov
ID: 6392843
yeah, second xsl:sort should be:

<xsl:sort select="name" data-type="text" order="ascending"/>
0
 
LVL 4

Accepted Solution

by:
edmund_mitchell earned 50 total points
ID: 6393363
hmfeng

The problem you're having is that you're mixing XSLT with Microsoft's old, proprietary dialect which is similar to XSLT.
Whenever you see the namespace:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
then it's not XSLT, and position() is an XSLT function.  I think they used a function called index() back in those days, but I'm not sure.
You'll be switching to this namespace:
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
That will change some things.  Order-by no longer exists, we now how the much more powerful xsl:sort.
I won't lie, you've got some learning ahead of you, but we'll be here to answer your questions (like this one).
My sincerest recommendation is that you switch to XSLT, since even Microsoft no longer supports that old dialect.  This is important, because XSLT 2.0 will be coming out soon, and you need to get caught up on XSLT 1.0!
Check out the MSXML FAQ at:
http://www.netcrucible.com/xslt/msxml-faq.htm
It will tell you everything you need to know to get current, and there is even a link to a stylesheet that will automatically upgrade your existing stylesheets to XSLT.

HTH,

Edmund
0
 
LVL 14

Expert Comment

by:avner
ID: 6393571
.
0
 
LVL 4

Expert Comment

by:vindevogel
ID: 6396137
0
 
LVL 4

Expert Comment

by:vindevogel
ID: 6396144
0
 
LVL 4

Expert Comment

by:vindevogel
ID: 6396155
<xsl:for-each select="row">
     <xsl:if test="position() mod 3 = 1">
          <tr>
               <td align="center">
                    <a style='cursor:hand'>
                         <xsl:attribute name="OnClick">
                              GotoApp('<xsl:value-of select="field[name='Mnemonic']/value"/>')
                         </xsl:attribute>
                         <img height="73" width="110">
                         <xsl:attribute name="src">./images/<xsl:value-of select="field[name='Mnemonic']/value"/>.jpg</xsl:attribute>
                              <xsl:attribute name="alt"><xsl:value-of select="field[name='Description']/value"/> (<xsl:value-of select="field[name='Mnemonic']/value"/>)</xsl:attribute>
                         </img>
                         <h3>
                              <xsl:value-of select="field[name='Mnemonic']/value"/>
                         </h3>
                    </a>
               </td>
               <xsl:if test="following-sibling::row/field[name='Mnemonic']/value!=''">
                    <td align="center">
                         <a style='cursor:hand'>
                              <xsl:attribute name="OnClick">
                                   GotoApp('<xsl:value-of select="following-sibling::row/field[name='Mnemonic']/value"/>')
                              </xsl:attribute>
                              <img height="73" width="110">
                              <xsl:attribute name="src">./images/<xsl:value-of select="following-sibling::row/field[name='Mnemonic']/value"/>.jpg</xsl:attribute>
                              <xsl:attribute name="alt"><xsl:value-of select="following-sibling::row/field[name='Description']/value"/> (<xsl:value-of select="following-sibling::row/field[name='Mnemonic']/value"/>)</xsl:attribute>
                              </img>
                              <h3>
                              <xsl:value-of select="following-sibling::row/field[name='Mnemonic']/value"/>
                              </h3>
                         </a>
                    </td>
               </xsl:if>
               <xsl:if test="following-sibling::row[position()=2]/field[name='Mnemonic']/value!=''">
                    <td align="center">
                         <a style='cursor:hand'>
                         <xsl:attribute name="OnClick">
                              GotoApp('<xsl:value-of select="following-sibling::row[position()=2]/field[name='Mnemonic']/value"/>')
                         </xsl:attribute>
                         <img height="73" width="110">
                         <xsl:attribute name="src">./images/<xsl:value-of select="following-sibling::row[position()=2]/field[name='Mnemonic']/value"/>.jpg</xsl:attribute>
                         <xsl:attribute name="alt"><xsl:value-of select="following-sibling::row[position()=2]/field[name='Description']/value"/> (<xsl:value-of select="following-sibling::row[position()=2]/field[name='Mnemonic']/value"/>)</xsl:attribute>
                         </img>
                         <h3>
                              <xsl:value-of select="following-sibling::row[position()=2]/field[name='Mnemonic']/value"/>
                         </h3>
                         </a>
                    </td>
               </xsl:if>
          </tr>
     </xsl:if>
</xsl:for-each>
0
 
LVL 4

Expert Comment

by:vindevogel
ID: 6396164
Hehe ... finally got it uploaded ...
appearantly, when you have to much tabs, you get a "no text"

The above thing is an example of how i use it.
Used to get 3 images on 1 row
0
 
LVL 2

Expert Comment

by:djokov
ID: 6396349
vindevogel

didn't you mess the question...
0
 

Author Comment

by:hmfeng
ID: 6397272
Thank you!

edmund_mitchell, this is the answer I want! I use IE5.0 and I installed the MSXML parser 4.0 , but when I use
http://www.w3.org/1999/XSL/Transform" the IE window would display nothing , I don't know why. Please give me the answer, I'm a beginner in xml and xslt. Thank you!
0
 

Author Comment

by:hmfeng
ID: 6421414
Thank you,edmund_mitchell, I found the way now!
0
 

Author Comment

by:hmfeng
ID: 6421415
Thank you very much!
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question