#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Creating a dynamic table with multiple columns


    Hi folks,

    I'm trying to code xslt to dynamically create a table from data in an an xml file like the following:

    Code:
    <item>
    <title>Birmingham Rose</title>
    <description>PB</description>
    <link>http://web02.wyndham.vic.gov.au/ipac20/ipac.jsp?index=ISBNEX&#38;term=9780330336581</link>
    <author>Annie Murray</author>
    <enclosure>http://syndetics.com/index.aspx?&#38;isbn=9780330336581/LC.GIF&#38;client=wyndlib&#38;upc=&#38;oclc=</enclosure>
    <guid isPermaLink="&#34;false&#34;">9780330336581</guid>
    <pubDate>Fri, 31 Dec 2010 10:31:36 +1100</pubDate>
    </item>
    <item>
    <title>House Rules</title>
    <description>FIC</description>
    <link>http://web02.wyndham.vic.gov.au/ipac20/ipac.jsp?index=ISBNEX&#38;term=9780743296434</link>
    <author>Jodi Picoult</author>
    <enclosure>http://syndetics.com/index.aspx?&#38;isbn=9780743296434/LC.GIF&#38;client=wyndlib&#38;upc=&#38;oclc=</enclosure>
    <guid isPermaLink="&#34;false&#34;">9780743296434</guid>
    <pubDate>Fri, 31 Dec 2010 10:31:36 +1100</pubDate>
    </item>
    The problem is, I'm putting data from multiple xml values in each table cell (see below for my xsl so far) - all of the examples that I've found so far using position() mod # = 0 and following-sibling:: commands etc. refer to cells with only a single xml value in them.

    Any suggestions or advice about how to tackle this would be much appreciated.


    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:param name="img_url" select="'http://g-images.amazon.com/images/G/01/x-site/icons/no-img-lg.gif'"/>
    
    <xsl:template match="/">
      <html>
      <body>
     
    <h2><xsl:value-of select="/rss/channel/title" disable-output-escaping="yes"/></h2>
    
    <table>
    <xsl:for-each select="rss/channel/item">
    <xsl:variable name="guid_val" select="guid"/>
    <xsl:variable name="link_src" select="link"/>
    <xsl:variable name="uri" select="concat('http://syndetics.com/index.aspx?&#38;isbn=', $guid_val, '/SC.GIF&#38;client=wyndlib&#38;upc=&#38;oclc=')"/>
    <tr>
    <td>
    <a href="{$link_src}"><xsl:value-of select="title"/></a><br/>
    <iframe name="I1" marginwidth="0" marginheight="0" border="0" align="absmiddle" frameborder="0" height="75" scrolling="no" width="50" vspace="0" hspace="0" src="{$uri}">Need inline 
    
    frames.</iframe>
    <br/>
    <xsl:value-of select="author"/>
    <br/>
    </td>
    </tr>
    </xsl:for-each>
    </table>
      </body>
      </html>
    </xsl:template>
    
    </xsl:stylesheet>
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,965
    Rep Power
    9397
    Without running it, it seems fine so far.
    Where's the problem? What output do you want to get?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0
    Originally Posted by requinix
    Without running it, it seems fine so far.
    Where's the problem? What output do you want to get?
    Hi there, thanks for replying.
    My issue was that I couldn't get output of data in dynamically generated table/columns - i.e. it displayed my content in a single column okay, but not in a "nice looking" table.

    I looked around some more and here's a solution that gives me a nice 6 column table:

    Code:
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="xml" indent="yes" encoding="iso-8859-1" doctype-public="-//W3C//DTD XHTML 1.1//EN" doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" omit-xml-declaration="yes"/>
      <xsl:template match="/">
        <html>
          <head>
            <title><xsl:value-of select="/rss/channel/title"/></title>
          </head>
          <body>
    <h2><xsl:value-of select="/rss/channel/title"/></h2>
            <table cellpadding="5" cellspacing="5" border="0" style="border-collapse: collapse; text-align: center;">
              <tbody>
                <xsl:apply-templates select="rss/channel/item[position() mod 6 = 1]" mode="tr"/>
              </tbody>
            </table>
          </body>
        </html>
      </xsl:template>
      <xsl:template match="item" mode="tr">
        <xsl:variable name="pos" select="(position() - 1) * 6 + 1"/>
        <tr>
          <xsl:apply-templates select="../item[position() &gt;= $pos and position() &lt; $pos + 6]" mode="td"/>
        </tr>
      </xsl:template>
      <xsl:template match="item" mode="td">
        <td>
    <xsl:variable name="guid_val" select="guid"/>
    <xsl:variable name="uri" select="concat('http://syndetics.com/index.aspx?&#38;isbn=', $guid_val, '/SC.GIF&#38;client=wyndlib&#38;upc=&#38;oclc=')"/>
    <iframe name="I1" marginwidth="0" marginheight="0" border="0" align="absmiddle" frameborder="0" height="75" scrolling="no" width="50" vspace="0" hspace="0" src="{$uri}">Need inline frames.</iframe>
          <br/>
          <xsl:variable name="link_src" select="link"/><a href="{$link_src}"><xsl:value-of select="title"/></a>
          <br/>
          <xsl:value-of select="author"/>
        </td>
      </xsl:template>
    </xsl:stylesheet>

IMN logo majestic logo threadwatch logo seochat tools logo