XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Sonika ColasoSubject: Repeat images using FOR EACH loop
Author: Sonika Colaso
Date: 27 Jul 2009 04:56 PM
Hello,

I'm new to XML & XSL and cannot figure out how to get this to work. Any help will be much appreciated!

I'm trying to loop through images and display it in each cell. For some reason, whatever i do, it just takes the first image and repeats that. I've tried many things, but cannot get it to read any other image. Here is a snippet of my XML code:

<report>
<quote >
<quote_attachment assoc_id="382,058">
<attachment location="3086.JPG"></attachment>
</quote_attachment>
<quote_attachment assoc_id="382,059">
<attachment location="FRONT_SKETCH_WITH_BUTTON_FLY3.JPG"></attachment>
</quote_attachment>
<quote_attachment assoc_id="382,060">
<attachment location="BACK_SKETCH7.JPG"></attachment>
</quote_attachment>
.
.
.

Now here is the XSL I am using to try to get it to loop the images into the table cells. It only picks the 3086.jpg image and repeats that into the cells. Please tell me what I am doing incorrectly, I've been struggling with this for a while now...thanks!!

<fo:table-row>
<xsl:for-each select="//quote_attachment/attachment/@location">

<fo:table-cell padding="0.25mm" border-style="solid" border-width=".25mm" height="2.0in">
<xsl:variable name="img_src" select="//quote_attachment/attachment/@location"/>
<fo:block font-weight="bold" font-size="6pt" text-align="center">
<fo:external-graphic src="{$img_src}" height="5.5in"/>
</fo:block>
</fo:table-cell>

</xsl:for-each>

</fo:table-row>

Postnext
Sonika ColasoSubject: Repeat images using FOR EACH loop
Author: Sonika Colaso
Date: 28 Jul 2009 10:11 AM
Hi all, I'm still waiting for someone to respond to my query. Please let me know if I need to provide more information. Thanks in advance for the help!

Postnext
Tony LavinioSubject: Repeat images using FOR EACH loop
Author: Tony Lavinio
Date: 29 Jul 2009 09:11 AM
When you say <xsl:variable name="img_src" select="//quote_attachment/attachment/@location"/> you are selecting all of the @locations again.

Since you are inside the scope of the for-each block, you should simply say <xsl:variable name=img_src" select="."/>

Postnext
Sonika ColasoSubject: Repeat images using FOR EACH loop
Author: Sonika Colaso
Date: 29 Jul 2009 09:20 AM
Originally Posted: 29 Jul 2009 09:21 AM
Awesome! Thanks Tony! That worked!! :) But I have another question now...kinda related...now I have 2 images showing up, atleast not repeating. But because I have specified 2 columns, it only wraps up into 2 cells and drops the third image. See code below. Any idea what I need to do to tell it to put the third image on the next row cell and so on? Basically 2 images per row but wrap to the next row if there are more than 2? Thanks again for the help!!

<!--Table for images -->
<xsl:template name="imagetable">
<fo:table table-layout="fixed">
<fo:table-column column-width="proportional-column-width(50)"/>
<fo:table-column column-width="proportional-column-width(50)"/>


<fo:table-body>


<fo:table-row>
<xsl:for-each select="//quote_attachment/attachment/@location">

<fo:table-cell padding="0.25mm" border-left-style="solid" border-right-style="solid" border-bottom-style="solid" border-width=".25mm" height="2.0in">
<xsl:variable name="img_src" select="."/>
<fo:block font-weight="bold" font-size="6pt" text-align="center">
<fo:external-graphic src="{$img_src}" height="5.5in"/>
</fo:block>
</fo:table-cell>

</xsl:for-each>
</fo:table-row>


</fo:table-body>
</fo:table>

Postnext
Tony LavinioSubject: Repeat images using FOR EACH loop
Author: Tony Lavinio
Date: 31 Jul 2009 09:16 AM
The usual method for handling things like this is to use the
'mod' function. If position() mod 2 = 0, then you're on an
even row - which in your case would be column 2. Otherwise,
you're on an odd row.

If you're going to be playing with XSLT, a good book to have
is the XSLT Cookbook by Sal Mangano.
See http://oreilly.com/catalog/9780596009748/

Postnext
Sonika ColasoSubject: Repeat images using FOR EACH loop
Author: Sonika Colaso
Date: 03 Aug 2009 09:43 AM
Thanks Toni. Could you please elaborate on this a bit? Is it something I can just include inside the code I posted? I think if I can get this figured out, should make a decent headway. So do let me know how I can incorporate that function into my code. Appreciate the help!

Posttop
Tony LavinioSubject: Repeat images using FOR EACH loop
Author: Tony Lavinio
Date: 10 Aug 2009 10:59 AM
Can you supply a sample input file a and small (mostly) working example?
Then it would be easier to see exactly what you are doing so we can make
a better suggestion.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.