Solved

Can I control the display number of recrod in xsl?

Posted on 2001-08-15
14
251 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
 
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

932 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

17 Experts available now in Live!

Get 1:1 Help Now