Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nick 19 posts 39 karma points
    May 25, 2012 @ 15:34
    Nick
    0

    Get image title tag into xslt

    Hi all,

    I have been making a slider for my webpage and this is what my XSLT looks like so far:

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
            version="1.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:umb="urn:umbraco.library"
            exclude-result-prefixes="umb"
    >

            <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />

            <xsl:param name="currentPage" />

            <xsl:variable name="mediaFolder" select="/macro/mediaFolder" />
            
            <xsl:template match="/">
                    <xsl:if test="($mediaFolder)">
                            <xsl:variable name="media" select="umb:GetMedia($mediaFolder/Folder/@id, true())" />
                            
                            <!-- If no errors, this will run the Folder template below -->
                            <xsl:apply-templates select="$media[not(error)]" />
                            
                    </xsl:if>
            </xsl:template>
            
            <!-- Template for the folder -->
            <xsl:template match="Folder">
                       <div id="slider" class="nivoslider">
                            <!-- Run templates for individual items (just add Media type aliases) -->
                            <xsl:apply-templates select="File | Image" />
                 
             

            
                   </div>      
            </xsl:template>
            
            <!-- Template for items - you can create individual templates to render them differently -->
            <xsl:template match="File | Image">
                  
        
         
                                  
              <img src="{umbracoFile}" title="$title"/>
         
                        
           


                        
                   
                      
            </xsl:template>

    </xsl:stylesheet>

     

    I want to be able to get a title tag for my image, as the NivoSlider uses this Title tag as a caption. Is there anyway to get a title tag from the media section when I upload an image?

    Any help would be appreciated.

    Thank you!

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    May 27, 2012 @ 01:34
    Chriztian Steinmeier
    0

    Hi Nick,

    For starters, you can use @nodeName and get a title that way (you should also add the alt attribute):

    <img src="{umbracoFile}" title="{@nodeName}" alt="{@nodeName}" />

    Then, if you'd like to give editors a better possibility of describing the images, I'd suggest you find the Media Type (Image, File etc.) in the Settins section and add a Description property (Textstring), which you can then use:

    <img src="{umbracoFile}" title="{description}" alt="{@nodeName}" />

    /Chriztian

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies