0

Been toying with this for some time... I have an xml file with the following lines

<image size="small">image_small.jpg</image>
<image size="medium">image_medium.jpg</image>
<image size="large">image_large.jpg</image>

ANy ideas on how I can just get the medium url for example.

currently I have... but its not doing the trick

<tr>
<td><img><xsl:attribute name="src">
          <xsl:value-of select="image/@size[@size=medium]" />
         </xsl:attribute>
    </img>
</td>
</tr>

Thanks in advance

Stevanicus
  • 7,561
  • 9
  • 49
  • 70

1 Answers1

3

Your question isn't very well defined since we don't have your whole XSLT nor the desired output, but I'll give it a try:

If you are using a for-loop to iterate over the different images you need to set your constraints on the loop itself, not the content of the loop.

If you put your example code inside a xsl:for-each it will iterate over every image but only fill the @src attribute when the image with @size="medium" is the current node. That would give you three table rows with three images but only one image with a valid @src attribute.

Instead change your xsl:for-each (or use xsl:apply-templates) to only iterate over your images with @size="medium":

<!-- This will only iterate over the medium sized images. -->
<xsl:for-each select="image[@size='medium']">
  <tr>
    <td>
      <img src="{.}"/>
    </td>
  </tr>
</xsl:for-each>

Another tip: instead of using xsl:attribute use an attribute value template.

Community
  • 1
  • 1
Per T
  • 2,008
  • 17
  • 14