Solved

Can I control the display number of recrod in xsl?

Posted on 2001-08-15
14
240 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
Comment Utility
:-)) strange question..
Please post your not working code...
0
 

Author Comment

by:hmfeng
Comment Utility
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
Comment Utility
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
 
LVL 2

Expert Comment

by:djokov
Comment Utility
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
Comment Utility
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
Comment Utility
.
0
 
LVL 4

Expert Comment

by:vindevogel
Comment Utility
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 4

Expert Comment

by:vindevogel
Comment Utility
0
 
LVL 4

Expert Comment

by:vindevogel
Comment Utility
<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
Comment Utility
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
Comment Utility
vindevogel

didn't you mess the question...
0
 

Author Comment

by:hmfeng
Comment Utility
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
Comment Utility
Thank you,edmund_mitchell, I found the way now!
0
 

Author Comment

by:hmfeng
Comment Utility
Thank you very much!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now