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

    Join Date
    Nov 2012
    Posts
    14
    Rep Power
    0

    PHP with XSLT - Images in table


    Hi!
    I have this problem where I want to show images in a table.
    In my PHP code I store image-URLs to a variable $link2. I'm generating an XML file with my PHP code and I'm also using an XSLT file to show the result.

    Part of my PHP code looks like this:
    PHP Code:
    <?php
    while ($line mysql_fetch_object($result)) {
            
    // store content in variables
            
    $link2 htmlspecialchars($line->link);
            
    $link2 ereg_replace (' ''%20'$link2);
            
    $link2 utf8_encode($link2);
            
    $date $line->date;
            
    $date utf8_encode($date);
            
    $tags htmlspecialchars($line->tag);
            
    $tags utf8_encode($tags);
            
            echo 
    "<image>
                <link><img src='
    $link2'/></link>
                <tags>
    $tags</tags>
                <date>
    $date</date>
                </image>"
    ;
        }
        
    ?>
    And in my XSL-file it looks like this:

    Code:
    <xsl:template match="image">
          <tr>
    		<td>
    			<xsl:value-of select="link"/>
    		</td>
            <td>
    			<xsl:value-of select="tags"/>
            </td>
    		<td>
    			<xsl:value-of select="date"/>
            </td>
          </tr>
    </xsl:template>
    My problem here is that I can't get the images to show up in my table. Isn't the xsl:value-of supposed to get the code between the <link> and the </link> in my PHP code? Which in my case is the img-element. Do I handle the $link2 variable wrong? The table ends up empty at the places where the images is supposed to be.
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,179
    Rep Power
    9398
    value-of copies the text representation of the node. Since the <img> is empty you get nothing.

    You want copy-of.
    Code:
    <xsl:copy-of select="link/*" />
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    14
    Rep Power
    0
    Originally Posted by requinix
    value-of copies the text representation of the node. Since the <img> is empty you get nothing.

    You want copy-of.
    Code:
    <xsl:copy-of select="link/*" />
    Thanks alot!
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    14
    Rep Power
    0
    Okay, thanks for the last answer. It helped me alot. Now I'm facing a new problem which probably is not very difficult to solve. The thing is that I want the table to create a new row every third column. And in the columns I want the information link,tags,date. As for now, it creates a new row after every column, which is understandable according to my code below. I have thought about just using a for-loop, but that doesn't seem like the right thing to use in XSL. I've also looked into the xsl:for-each element, but can't solve it by myself.

    Here is my updated code in the XSL-file. The PHP-code is still the same as before.
    Code:
    <xsl:template match="image">
          <tr>
    		<td>
    			<xsl:copy-of select="link/*"/><br/>
    			<b>Tags: </b><xsl:value-of select="tags"/><br/>
    			<b>Added: </b><xsl:value-of select="date"/>
    		</td>		
          </tr>
    </xsl:template>

IMN logo majestic logo threadwatch logo seochat tools logo