Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 2nd, 2005, 12:01 PM
Registered User
 
Join Date: Nov 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Re: Dynamic html tables with xsl?

 Hey,
    Please can you help me ive been trying to solve this problem for the last few days and i know its going to be something simple i just cant work it out (i am a complete newbie!).

 What im trying to do is create a table for a dynamic number of images, displaying 4 images for each row.

 I can get this part working fine but i then wanted to have 4 images in a row followed by some information about that image such as title, etc
Problem is when i try to put this code is (similar to how i did the
images) it just wont display right.

So if i have 20 images for example 4 images will be displayed then on the next row 20 "view more information" text will be displayed and then on the next row 4 more images and next row 4 more images until 20 images are displayed.

I have been changing the xsl file a bit to try to get it to work and know the problem is something with these lines....

      <tr>
        <xsl:apply-templates
select="(indxRes/RESULT/IMAGE-INFO[position()=$CurPos or
position=$CurPos+1 or position()=$CurPos+2 or position()=$CurPos+3])">
        </xsl:apply-templates>
      </tr>

    If i remove the [position.... bit i get 4 images displayed followed by 20 "view more information" followed by 4 images followed by 20 "view more information" and so on.

 So this proves that the iteration for each row is working. The problem is something to do with selecting the 4 particular parts of information (IMAGE-INFO elements).

 Please find my full xsl and xml file below:-


************************************************** ********************
xsl
************************************************** ********************

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
        <xsl:output method="html" indent="yes" omit-xml-declaration="yes"/>

        <xsl:template match ="RESULT_LIST">
       <table width="100%" border="1" align="center" cellpadding="5"
cellspacing="5">
            <xsl:call-template name="Rows">
              <xsl:with-param name="CurPos" select="1" />
            </xsl:call-template>
       </table>
    </xsl:template>

   <xsl:template name="Rows">
      <xsl:param name="CurPos" />
      <tr>
        <xsl:apply-templates select="indxRes[position()=$CurPos or
position()=$CurPos+1 or position()=$CurPos+2 or position()=$CurPos+3]">
        </xsl:apply-templates>
      </tr>
      <tr>
        <xsl:apply-templates
select="(indxRes/RESULT/IMAGE-INFO[position()=$CurPos or
position=$CurPos+1 or position()=$CurPos+2 or position()=$CurPos+3])">
        </xsl:apply-templates>
      </tr>

      <xsl:if test="indxRes[position() > $CurPos+3]">
        <xsl:call-template name="Rows">
          <xsl:with-param name="CurPos"
select="$CurPos+4"></xsl:with-param>
        </xsl:call-template>
      </xsl:if>
   </xsl:template>

        <xsl:template match="indxRes">
        <td align="center" valign="middle" width="23%">
                <xsl:element name="div">
                        <xsl:attribute name="class">result</xsl:attribute>
                        <xsl:attribute name="id"><xsl:value-of
select="@type"/><xsl:value-of select="@indx"/></xsl:attribute>
                        <h4>

                            <xsl:element name="a">
                                <xsl:attribute name="href">
<xsl:value-of select=="RESULT/IMAGE-DISPLAY/URL"/></xsl:attribute>
<xsl:element name="img"> <xsl:attribute name="src"> <xsl:value-of select="RESULT/IMAGE-DISPLAY/THUMB-URL" />
</xsl:attribute>
<xsl:attribute name="border">3</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="RESULT/IMAGE-DISPLAY/TITLE" />
                                              </xsl:attribute>
                                                <xsl:attribute
name="align">left</xsl:attribute>
                                                <xsl:attribute
name="height"><xsl:value-of
select="RESULT/IMAGE-DISPLAY/THUMB-HEIGHT"/></xsl:attribute>
                                                <xsl:attribute
name="width"><xsl:value-of
select="RESULT/IMAGE-DISPLAY/THUMB-WIDTH"/></xsl:attribute>
                                                <xsl:attribute
name="title">Score : <xsl:value-of
select="floor(RESULT/@SCORE)"/></xsl:attribute>
                                         </xsl:element>
                            </xsl:element>

                        </h4>
                 </xsl:element>
            </td>
    </xsl:template>

    <xsl:template match = "IMAGE-INFO">
            <td align="center" valign="middle" width="23%">
            View more information
            </td>
    </xsl:template>

</xsl:stylesheet>

************************************************** *******************
  xml
************************************************** *******************


<RESULT_LIST>
<indxRes type ="m" indx="18">
<RESULT SCORE="19.0">
    <IMAGE-DISPLAY> <URL>http://7art-screensavers.com/screenshots/fruits/oranges-on-the-tree.jpg</URL>
        <TITLE>oranges on the tree</TITLE>
        <THUMB-URL>http://scd.mm-b1.yimg.com/image/532336800</THUMB-URL>
        <THUMB-HEIGHT>101</THUMB-HEIGHT>
        <THUMB-WIDTH>135</THUMB-WIDTH>
    </IMAGE-DISPLAY>
    <IMAGE-INFO>
        <DISPLAYURL>http://7art-screensavers.com/screenshots/fruits/oranges-on-the-tree.jpg</DISPLAYURL>
        <BLURB>orangefruit orangegrapefruitbananagrapespearappletangerine orangesonthetree peaches</BLURB>
        <IMAGE-HOST>http://www.7art-screensavers.com/fruits.shtml</IMAGE-HOST>
        <IMAGE-SIZE>84410</IMAGE-SIZE>
        <IMGFORMAT>jpeg</IMGFORMAT>
        <IMGHEIGHT>600</IMGHEIGHT>
        <IMGWIDTH>800</IMGWIDTH>
        <CLICKURL>http://7art-screensavers.com/screenshots/fruits/oranges-on-the-tree.jpg</CLICKURL>
    </IMAGE-INFO>
    <RESULT-POSITION>
        <ENGINE>YahooImages</ENGINE>
        <POSITION>19</POSITION>
    </RESULT-POSITION>
</RESULT>
</indxRes>
<indxRes type ="m" indx="19">
<RESULT SCORE="20.0">
    <IMAGE-DISPLAY>
        <URL>http://jeffcroft.com/downloads/desktops/Save_The_Oranges.jpg</URL>
        <TITLE>Save The Oranges</TITLE>
        <THUMB-URL>http://scd.mm-a1.yimg.com/image/155902269</THUMB-URL>
        <THUMB-HEIGHT>96</THUMB-HEIGHT>
        <THUMB-WIDTH>145</THUMB-WIDTH>
    </IMAGE-DISPLAY>
    <IMAGE-INFO>
        <DISPLAYURL>http://jeffcroft.com/downloads/desktops/Save_The_Oranges.jpg</DISPLAYURL>
        <BLURB>Taupe The Orange Ones Save the Oranges 1280x854</BLURB>
        <IMAGE-HOST>http://jeffcroft.com/downloads/desktops</IMAGE-HOST>
        <IMAGE-SIZE>196252</IMAGE-SIZE>
        <IMGFORMAT>jpeg</IMGFORMAT>
        <IMGHEIGHT>854</IMGHEIGHT>
        <IMGWIDTH>1280</IMGWIDTH>
        <CLICKURL>http://jeffcroft.com/downloads/desktops/Save_The_Oranges.jpg</CLICKURL>
    </IMAGE-INFO>
    <RESULT-POSITION>
        <ENGINE>YahooImages</ENGINE>
        <POSITION>20</POSITION>
    </RESULT-POSITION>
</RESULT>
</indxRes>
<indxRes type ="m" indx="16">
<RESULT SCORE="17.0">
    <IMAGE-DISPLAY>
        <URL>http://www.4juicers.com/images/oranges.jpg</URL>
        <TITLE>oranges</TITLE>
        <THUMB-URL>http://scd.mm-a1.yimg.com/image/247206994</THUMB-URL>
        <THUMB-HEIGHT>70</THUMB-HEIGHT>
        <THUMB-WIDTH>110</THUMB-WIDTH>
    </IMAGE-DISPLAY>
    <IMAGE-INFO>
        <DISPLAYURL>http://www.4juicers.com/images/oranges.jpg</DISPLAYURL>
        <BLURB>Citrus Juicers Did You Know Foods rich in potassium such as ORANGES may help reduce the risk of stroke and can reduce blood pressure according to an 8year Harvard study published in the</BLURB>
        <IMAGE-HOST>http://www.4juicers.com/citrus.html</IMAGE-HOST>
        <IMAGE-SIZE>18926</IMAGE-SIZE>
        <IMGFORMAT>jpeg</IMGFORMAT>
        <IMGHEIGHT>151</IMGHEIGHT>
        <IMGWIDTH>235</IMGWIDTH>
        <CLICKURL>http://www.4juicers.com/images/oranges.jpg</CLICKURL>
    </IMAGE-INFO>
    <RESULT-POSITION>
        <ENGINE>YahooImages</ENGINE>
        <POSITION>17</POSITION>
    </RESULT-POSITION>
</RESULT>
</indxRes>
<indxRes type ="m" indx="17">
<RESULT SCORE="18.0">
    <IMAGE-DISPLAY>
        <URL>http://www.hve.com/science/hn/Food_Guide/Oranges.jpg</URL>
        <TITLE>Oranges</TITLE>
        <THUMB-URL>http://scd.mm-c1.yimg.com/image/1005870595</THUMB-URL>
        <THUMB-HEIGHT>105</THUMB-HEIGHT>
        <THUMB-WIDTH>105</THUMB-WIDTH>
    </IMAGE-DISPLAY>
    <IMAGE-INFO>
        <DISPLAYURL>http://www.hve.com/science/hn/Food_Guide/Oranges.jpg</DISPLAYURL>
        <IMAGE-HOST>http://www.hve.com/science/hn/Food_Guide/Oranges.htm</IMAGE-HOST>
        <IMAGE-SIZE>28105</IMAGE-SIZE><IMGFORMAT>jpeg</IMGFORMAT>
        <IMGHEIGHT>200</IMGHEIGHT>
        <IMGWIDTH>200</IMGWIDTH>
        <CLICKURL>http://www.hve.com/science/hn/Food_Guide/Oranges.jpg</CLICKURL>
    </IMAGE-INFO>
    <RESULT-POSITION>
        <ENGINE>YahooImages</ENGINE>
        <POSITION>18</POSITION>
    </RESULT-POSITION>
</RESULT>
</indxRes>
<indxRes type ="m" indx="18">
<RESULT SCORE="19.0">
    <IMAGE-DISPLAY>
        <URL>http://www.poster.net/fabiano-marco/fabiano-marco-majolica-oranges-2400993.jpg</URL>
        <TITLE>fabiano marco majolica oranges 2400993</TITLE>
        <THUMB-URL>http://scd.mm-a1.yimg.com/image/307061763</THUMB-URL>
        <THUMB-HEIGHT>120</THUMB-HEIGHT>
        <THUMB-WIDTH>120</THUMB-WIDTH>
    </IMAGE-DISPLAY>
    <IMAGE-INFO>
        <DISPLAYURL>http://www.poster.net/fabiano-marco/fabiano-marco-majolica-oranges-2400993.jpg</DISPLAYURL>
        <IMAGE-HOST>http://www.poster.de/Fabiano-Marco/Fabiano-Marco-Majolica-Oranges-2400993.html</IMAGE-HOST>
        <IMAGE-SIZE>41972</IMAGE-SIZE>
        <IMGFORMAT>jpeg</IMGFORMAT>
        <IMGHEIGHT>450</IMGHEIGHT>
        <IMGWIDTH>450</IMGWIDTH>
        <CLICKURL>http://www.poster.net/fabiano-marco/fabiano-marco-majolica-oranges-2400993.jpg</CLICKURL>
    </IMAGE-INFO>
    <RESULT-POSITION>
        <ENGINE>YahooImages</ENGINE>
        <POSITION>19</POSITION>
    </RESULT-POSITION>
</RESULT>
</indxRes>
<indxRes type ="m" indx="19">
<RESULT SCORE="20.0">
    <IMAGE-DISPLAY>
        <URL>http://www.zawaj.com/youssuf/photos/oranges.jpg</URL>
        <TITLE>oranges</TITLE>
        <THUMB-URL>http://scd.mm-a1.yimg.com/image/187805690</THUMB-URL>
        <THUMB-HEIGHT>110</THUMB-HEIGHT>
        <THUMB-WIDTH>94</THUMB-WIDTH>
    </IMAGE-DISPLAY>
    <IMAGE-INFO>
        <DISPLAYURL>http://www.zawaj.com/youssuf/photos/oranges.jpg</DISPLAYURL>
        <BLURB>to us as the best in town I told my grandfather that we should return to Ahmed and demand that he return our money and give us the proper oranges I was furious My grandfather sat me down and said Calm down is it worth arguing with your Muslim brother about some oranges I thought about it for a second or two and said But</BLURB>
        <IMAGE-HOST>http://www.zawaj.com/youssuf/11-3-2000.html</IMAGE-HOST>
        <IMAGE-SIZE>15948</IMAGE-SIZE>
        <IMGFORMAT>jpeg</IMGFORMAT>
        <IMGHEIGHT>263</IMGHEIGHT>
        <IMGWIDTH>225</IMGWIDTH>
        <CLICKURL>http://www.zawaj.com/youssuf/photos/oranges.jpg</CLICKURL>
    </IMAGE-INFO>
    <RESULT-POSITION>
        <ENGINE>YahooImages</ENGINE>
        <POSITION>20</POSITION>
    </RESULT-POSITION>
</RESULT>
</indxRes>
</RESULT_LIST>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic tables soulfly73 Classic ASP Basics 3 November 17th, 2008 07:06 PM
Dynamic html file call in XSL suri XSLT 4 June 22nd, 2007 08:03 AM
Dynamic tables in DataSet melvik C# 9 September 26th, 2006 06:53 AM
Multiple Tables Display in XSL bmagadi XSLT 1 February 8th, 2005 03:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.