Solved

Can I control the display number of recrod in xsl?

Posted on 2001-08-15
14
289 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

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…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

724 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