?
Solved

Can I control the display number of recrod in xsl?

Posted on 2001-08-15
14
Medium Priority
?
290 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

 
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 200 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

752 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