|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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:
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? |
|
#2
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
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" ?> |
|
#4
|
||||
|
||||
|
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- |
|
#5
|
|||
|
|||
|
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) 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 |
|
#6
|
||||
|
||||
|
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" ![]() |
|
#7
|
|||
|
|||
|
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. |
|
#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). ![]() |
|
#9
|
||||
|
||||
|
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...
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Newbie XML/XSL question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|