Search

I have a series of images attached to my xml and I am struggling to figure out what path to use to grab it to place into my html:

I have a template match of data and a section called other-information

Within other-information I have this xml output.

<images items="3">
<item>
<name handle="this-is-a-new-image-test">This is a new image test</name>
<upload-image size="1.48 mb" path="/submitted/images" type="image/jpeg">
<filename>ManUTD-Trip-110-1259098585.jpg</filename>
<meta creation="2009-11-24T21:36:25+00:00" width="3072" height="2304" />
</upload-image>
</item>
<item>
<name handle="routes-into-language">routes into language</name>
<upload-image size="53 kb" path="/submitted/images" type="image/jpg">
<filename>routes_into_languages_cymru_black-1259170827.jpg</filename>
<meta creation="2009-11-25T17:40:27+00:00" width="150" height="143" />
</upload-image>
</item>
<item>
<name handle="other-info-image-2">Other info image 2</name>
<upload-image size="19 kb" path="/submitted" type="image/jpg">
<filename>auction-in-progress-1252432554.jpg</filename>
<meta creation="2009-09-08T18:55:53+01:00" width="300" height="170" />
</upload-image>
</item>
</images>
<position>
<item handle="right">right</item>
</position>

What I need is a heads up on how to target the correct url to the image file with JIT Image Manipulation so as to be able to scale the output to a max of 320px wide..

And also I am wanting a for-each loop to retrieve all of the images one after the other and using the class inside the position field to determine which css class to use for all images.. heads up on how I would target this as well would be ideal.. I am using Nils Mediatek extension to list the images and this is proving to be a life saver as far is limiting how many potential mess ups the client can do with images.. i.e Nickdunn mentioned clients uplaoding 10mb files.. been there :) the above ones are big enough in the XML but these were just tests anyway. Any help here would be greeet :)

Why code no show? :(

Tried this:

<div class="image">
<xsl:for-each select="entry">
<img class="{position/item}" src="{$root}{images/item/upload-image/path}/2/320/0/5/{images/item/upload-image/filename}" title="{images/item/name}"/>
</xsl:for-each>
</div>

But all I get is the first image of every entry in the DB.. I want all the images from 1 entry but not sure how to target the <images items=3"> or at least loop over this node to display all 3 images.

When you for-each something, the context changes to whatever the iterated target was. In this case item (you had entry, but the mediathek field uses items for each image) becomes the context, so you can access the other nodes directly.

To access the path, it’s an attribute so the @ is used to select it.

Also not quite sure what the class="{position/item}" is meant to be. I think you want the class to the be the number of the image (which is bad), but it’s below anyway.

Try:

<div class="image">
    <xsl:for-each select="images/item">
        <img class="image-{position()}" src="{$root}{upload-image/@path}/2/320/0/5/{upload-image/filename}" title="{name}"/>
    </xsl:for-each>
</div>

Also the code no show seems to be if you post the code block first without any text preceding it. I just ran into the same trap myself :)

makenosound helped me get to this through the chat room!

<div class="image">
<xsl:for-each select="entry">
<xsl:variable name="position" select="position/item/@handle"/>
<xsl:for-each select="images/item">
<img class="{$position}" src="{$root}/image/1/300/0{upload-image/@path}/{upload-image/filename}" title="{name}"/>
</xsl:for-each>
</xsl:for-each>
</div>

Ah touche. Almost similar. Disregard my comments about position, didn’t see it until now in the original source.

Heres a little extra I’ve been playing with but wanted a heads up on the JIT Image manipulation bit or just as to whether the value within the url for the JIT can by dynamically set from a Field section?

<div class="image">
<xsl:for-each select="images">
<xsl:variable name="position" select="../position/item/@handle"/>
<xsl:variable name="size" select="../size/item"/>
<xsl:for-each select="item">
<img class="{$position}" src="{$root}/image/1/{$size}/0{upload-image/@path}/{upload-image/filename}" title="{name}"/>
</xsl:for-each>
</xsl:for-each>
</div>

The {$size} is referencing a select box with a few size options for the image box.. when I publish this though, It just jettisons the {$size} bit and I get a // as in empty variable.. hmmm

Could you post the XML output?

It may be that you have to add the @handle or something similar.

http://www.pastie.org/716881

With Rowans help and guidance we managed to get this going.. and then we broke it by adding a default param for the image size..

<xsl:variable name="size" select="350"/>

Placing the above variable any where other than above the master apply temaplates.. causes a major XML error wobbly to do with Refreshing Size I think..

bloody code.. what gives?

Pastie gives back! cheers nickdunn

Use Gist or Pastie. If you try posting tag-based code and it’s not properly indented then the forum throws a wobbly.

Ok cool, If the one line of code is too long it wraps to the next line, but won’t indent cos it’s part of the previous line.. so pastie it is! www.pastie.org must have a massive datatbase of code inserts by now.. are they there for a specific time period or indefinately?

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details