XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 28th, 2012, 06:30 PM
emilagren emilagren is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 14 emilagren User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 9 m 22 sec
Reputation Power: 0
PHP-General - 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.

Reply With Quote
  #2  
Old November 28th, 2012, 06:49 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,696 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 4 h 42 m 26 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to 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/*" />

Reply With Quote
  #3  
Old November 29th, 2012, 04:15 AM
emilagren emilagren is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 14 emilagren User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 9 m 22 sec
Reputation Power: 0
Quote:
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!

Reply With Quote
  #4  
Old December 2nd, 2012, 02:37 PM
emilagren emilagren is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 14 emilagren User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 9 m 22 sec
Reputation 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>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > PHP-General - PHP with XSLT - Images in table

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap