XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
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 July 9th, 2004, 08:53 AM
loucapo loucapo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: Long Island, NY
Posts: 4 loucapo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to loucapo
Newbie XML/XSL question

Hi I'm new to XML/XSL and am obviously having some troubles. I have a photo library website that has a photo search function. It returns your search results as XML:

<?xml version="1.0" ?>
<photoResults order="ascending" total="27">
<photo>
<imageNumber>02L00049.jpg</imageNumber>
<imageDescription>Limo parked on city street</imageDescription>
<imageExpDate>Will not expire</imageExpDate>
<imagePhotog>Y. Seidel</imagePhotog>
<imageHighFileSize>3.1MB</imageHighFileSize>
<imageMediumFileSize>508KB</imageMediumFileSize>
<imageDateEntered>5/18/2001 12:13:41 PM</imageDateEntered>
<imageSearchMatch>83</imageSearchMatch>
</photo>
<photo>
<imageNumber>01L00099.jpg</imageNumber>
<imageDescription>Business people sitting in lobby</imageDescription>
<imageExpDate>08/01/2004</imageExpDate>
<imagePhotog>T. Kawalerski</imagePhotog>
<imageHighFileSize>4.67MB</imageHighFileSize>
<imageMediumFileSize>385KB</imageMediumFileSize>
<imageDateEntered>5/18/2001 12:13:42 PM</imageDateEntered>
<imageSearchMatch>85</imageSearchMatch>
</photo>
<photo>
<imageNumber>03L00158.jpg</imageNumber>
<imageDescription>Two businessmen discussing floor plans</imageDescription>
<imageExpDate>08/01/2004</imageExpDate>
<imagePhotog>T. Kawalerski</imagePhotog>
<imageHighFileSize>3.24MB</imageHighFileSize>
<imageMediumFileSize>235KB</imageMediumFileSize>
<imageDateEntered>5/18/2001 12:13:44 PM</imageDateEntered>
<imageSearchMatch>85</imageSearchMatch>
</photo>

I need an XSL document to spit out the results with 2 photos per row. I am able to get my results to display cleanly 1 per row, but can't find how to get 2. Any ideas?

Reply With Quote
  #2  
Old July 9th, 2004, 09:16 AM
Miska's Avatar
Miska Miska is offline
Madden Maniac
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2001
Location: Finland
Posts: 519 Miska User rank is Lance Corporal (50 - 100 Reputation Level)Miska User rank is Lance Corporal (50 - 100 Reputation Level)Miska User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Day 3 h 47 m 50 sec
Reputation Power: 8
Can you post your XSLT file, so that we can see more clearly what you''re trying to do... It can prob be quite easily done by using if-statements and xsl-param

Last edited by Miska : July 9th, 2004 at 09:20 AM.

Reply With Quote
  #3  
Old July 9th, 2004, 09:38 AM
loucapo loucapo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: Long Island, NY
Posts: 4 loucapo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to loucapo
This is my XSL file. The transform gets called by a basic html page that does a "HTMLtarget.innerHTML = XMLDocument.transformNode(XSLDocument); "

Thanks,
Lou
<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.1">

<xsl:template match="/">
<HTML>
<BODY>
<TABLE BORDER="0">
<xsl:apply-templates select="/photoResults/photo">
<xsl:sort select="imageSearchMatch" order="ascending"/>
</xsl:apply-templates>
</TABLE>
</BODY>
</HTML>
</xsl:template>

<xsl:template match="photo">
<xsl:if test="(position() mod 2 = 0)">
<tr>
</xsl:if>
<td>
<Table>
<TR>
<TD>
<xsl:value-of select="imageNumber"/><br />
<img height="123" width="123">
<xsl:attribute name="src">/national/gallery.nsf/admin/brandpacks/brandpackgallery/
<xsl:value-of select="imageNumber"/>/$file/
<xsl:value-of select="imageNumber"/>
</xsl:attribute>
</img>
<br />
Expires: <xsl:value-of select="imageExpDate"/>
</TD>
<TD><xsl:value-of select="imageHighFileSize"/></TD>
<TD><xsl:value-of select="imageDescription"/></TD>
</TR>
</Table>
</td>
<xsl:if test="(position() mod 2 = 1)">
</tr>
</xsl:if>
</xsl:template>

</xsl:stylesheet>

Reply With Quote
  #4  
Old July 12th, 2004, 03:44 AM
Miska's Avatar
Miska Miska is offline
Madden Maniac
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2001
Location: Finland
Posts: 519 Miska User rank is Lance Corporal (50 - 100 Reputation Level)Miska User rank is Lance Corporal (50 - 100 Reputation Level)Miska User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Day 3 h 47 m 50 sec
Reputation Power: 8
Hi!

Here's a solution for your problem (I hope):

Code:
<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.1">
<xsl:template match="photoResults">
<html>
<body>
<table>
<xsl:for-each select='photo'>
<xsl:if test='position() mod 2 = 1'>
<tr>
<xsl:call-template name='row'>
<xsl:with-param name='position' select='position()'/>
<xsl:with-param name='parent' select='..'/>
<xsl:with-param name='times' select='2'/>
</xsl:call-template>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

<xsl:template name='row'>
<xsl:param name='position'/>
<xsl:param name='parent'/>
<xsl:param name='times'/>
<xsl:if test='$times > 0'>
   <xsl:choose>
	    <xsl:when test='$position > last()'>
			   <td> </td>
				 <td> </td>
				 <td> </td>
			</xsl:when>
			<xsl:otherwise>
				 <td><xsl:value-of select='$parent/photo[$position]/imageNumber'/><br/><img height="123" width="123"><xsl:attribute name="src">/national/gallery.nsf/admin/brandpacks/brandpackgallery/<xsl:value-of select='$parent/photo[$position]/imageNumber'/>/$file/<xsl:value-of select='$parent/photo[$position]/imageNumber'/></xsl:attribute></img><br/>Expires: <xsl:value-of select='$parent/photo[$position]/imageExpDate'/></td>
				 <td><xsl:value-of select='$parent/photo[$position]/imageHighFileSize'/></td>
				 <td><xsl:value-of select='$parent/photo[$position]/imageDescription'/></td>
		</xsl:otherwise>
	</xsl:choose>
	<xsl:call-template name='row'>
	   <xsl:with-param name='position' select='$position + 1'/>
		 <xsl:with-param name='parent' select='$parent'/>
		 <xsl:with-param name='times' select='$times - 1'/>
	</xsl:call-template>
</xsl:if>
</xsl:template>

</xsl:stylesheet>


This piece of xsl can be easily modified to print out x photos / row as all you need to change is the mod number and the times parameter. Hope this helps you...

-Miska-

Reply With Quote
  #5  
Old July 12th, 2004, 09:35 AM
loucapo loucapo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: Long Island, NY
Posts: 4 loucapo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to loucapo
sweet...it works

Hey that works like a charm, but it causes 1 thing I had done to stop working.

My html page had the following function
function sort(sortNode)
{
(XSLDocument.selectSingleNode("//xsl:sort/@select")).nodeValue = sortNode;
HTMLtarget.innerHTML = XMLDocument.transformNode(XSLDocument);
}

its is called from a drop down field & when i try to use it with your style sheet, I get the following error:
XSLDocument.selectSingleNode(...) is null or not an object

Could this be related to something in the stylesheet u wrote?

Thanks,
Lou

Reply With Quote
  #6  
Old July 13th, 2004, 02:40 AM
Miska's Avatar
Miska Miska is offline
Madden Maniac
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2001
Location: Finland
Posts: 519 Miska User rank is Lance Corporal (50 - 100 Reputation Level)Miska User rank is Lance Corporal (50 - 100 Reputation Level)Miska User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Day 3 h 47 m 50 sec
Reputation Power: 8
Yep, that's true... If you take a look at my version and your's, you'll see the difference in <xsl:apply-templates> as I'm not doing that at all... And because of of this your sort @select will fail...

I think you can still apply-templates at some point, but be "careful" where to put it... "Trying to teach you"

Reply With Quote
  #7  
Old July 14th, 2004, 08:24 AM
loucapo loucapo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: Long Island, NY
Posts: 4 loucapo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to loucapo
Ok, so I'm trying to get my head around this but I'm having some trouble. Am I supposed to change the call-template tags you have to apply-templates? Or do I just need to add an apply-templates somewhere creatively?

I tried putting
<xsl:sort select="imageNumber" order="ascending"/>

in the xsl:for-each, but it seems to get ignored. I thought that should work.

Reply With Quote
  #8  
Old July 15th, 2004, 02:33 AM
Miska's Avatar
Miska Miska is offline
Madden Maniac
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2001
Location: Finland
Posts: 519 Miska User rank is Lance Corporal (50 - 100 Reputation Level)Miska User rank is Lance Corporal (50 - 100 Reputation Level)Miska User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Day 3 h 47 m 50 sec
Reputation Power: 8
Actually it's a bit more trickier than I first thought it would be. The call-tamplate uses the original node set so the position function returns the "original" node set, therefor the sort doesn't apply inside the for-each.

My vacation starts tomorrow, so I don't have any time to help you more, but hope you figure this out... (Plz post here if you can figure it out - I think you need to make a few changes here and there).

Reply With Quote
  #9  
Old July 15th, 2004, 09:00 AM
Miska's Avatar
Miska Miska is offline
Madden Maniac
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2001
Location: Finland
Posts: 519 Miska User rank is Lance Corporal (50 - 100 Reputation Level)Miska User rank is Lance Corporal (50 - 100 Reputation Level)Miska User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Day 3 h 47 m 50 sec
Reputation Power: 8
If you are looking for an easier solution, what you could do is have one transform sort it out correctly and use the the output of that transformation as input to this print 2 objects / row transformation...


Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Newbie XML/XSL question


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

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT