Copied to clipboard

Flag this post as spam?

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


  • Sam 184 posts 209 karma points
    Mar 27, 2011 @ 13:49
    Sam
    0

    Getting image from doctype

    Hi everyone,

    I've been having a problem again getting an image from a doctype (which I choose via the mediapicker). Here is my code so far:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
      exclude-result-prefixes="msxml
    umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes
    Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings
    Exslt.ExsltSets "
    >

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

            <xsl:param name="currentPage" />
            
      <xsl:template match="/">
        <ul id="listGalleries"><xsl:apply-templates select="$currentPage/descendant::* [@isDoc][not(umbracoNaviHide = 1)]" />
        </ul>
        </xsl:template>
              
      <xsl:template match="* [@isDoc]">
        
        <li>
          <a href="{umbraco.library:NiceUrl(@id)}">
            <xsl:choose>
              <xsl:when test="galleryThumbnailImage !=''">
                <xsl:variable name="thumb" select="umbraco.library:GetMedia(galleryThumbnailImage, false())" />
                <img src="/ImageGen.ashx?image={$thumb}&amp;width={$listThumbnailWidth}" alt="{@nodeName}" />
              </xsl:when>
              <xsl:otherwise>
                <p>no image</p>
              </xsl:otherwise>
            </xsl:choose>
          </a>
        </li>

        </xsl:template>

    </xsl:stylesheet>

    I also don;t know why the top of my xml files seems a little different with different examples given here on the forum. For example, one starts with:

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

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

    and another with:

    <?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" />

    and a third one:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
      exclude-result-prefixes="msxml
    umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes
    Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings
    Exslt.ExsltSets "
    >


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

     

    Bit confused with that. Any explanations would be greatly received.

    I have trie a few combos with getting getmedia to work (including just using umb:GetMedia - still don't know the difference between that and umbraco.library:getMedia?!) but no luck, I just can't see what I'm doing wrong.

    Thanks in advance if anyone can shed some light :)

    Sam.

  • Kim Andersen 1447 posts 2196 karma points MVP
    Mar 27, 2011 @ 15:35
    Kim Andersen
    0

    Hi Sam

    Try this approach instead:

    <xsl:variable name="listThumbnailWidth" select="200" />
    <
    xsl:choose>
              <xsl:when test="galleryThumbnailImage !=''">
                <xsl:variable name="thumb" select="umbraco.library:GetMedia(galleryThumbnailImage, false())" />
                <img src="/ImageGen.ashx?image={$thumb/umbracoFile}&amp;width={$listThumbnailWidth}" alt="{@nodeName}" />
              </xsl:when>
              <xsl:otherwise>
                <p>no image</p>
              </xsl:otherwise>
            </xsl:choose>

    I couldn't see the listThumbnailWith any where in the code, so this should be created.

    The difference between umb and umbraco.library is actually just how you want to reffer the extensions library. I think the umb-prefix comes from some of Chriztian Steinmeier's example :) You can use both methods.

    /Kim A

  • Sam 184 posts 209 karma points
    Mar 27, 2011 @ 16:29
    Sam
    0

    Thanks Kim but that didn't work for me either. I have however just cracked it :))

    Here's the code, maybe useful to anyone else:

    <?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:template match="/">
                    <ul id="listGalleries">
                      <xsl:apply-templates select="$currentPage/descendant::* [@isDoc][not(umbracoNaviHide = 1)]" />
                    </ul>
            </xsl:template>
      
      <xsl:template match="* [@isDoc]">
                    <li>
                      <a href="{umb:NiceUrl(@id)}">
    <xsl:choose>
      <xsl:when test="galleryThumbnailImage != ''">
        <xsl:variable name="thumb" select="umb:GetMedia(galleryThumbnailImage, false())" />
        <xsl:variable name="thumbWidth" select="$currentPage/galleryThumbnailWidth" />
        <img src="/ImageGen.ashx?image={$thumb/umbracoFile}&amp;width={$thumbWidth}" alt="{@nodeName}" />
      </xsl:when>
    <xsl:otherwise>
      <p>nothing here...</p>
    </xsl:otherwise>
    </xsl:choose>     
                      </a>
                    </li>
            </xsl:template>

    </xsl:stylesheet>

    Thanks again Kim, you pointed me in the right direction.

    Sam.

     

     

     

  • Kim Andersen 1447 posts 2196 karma points MVP
    Mar 27, 2011 @ 16:58
    Kim Andersen
    1

    Great that you got it solved Sam!

    /Kim A

  • Sam 184 posts 209 karma points
    Mar 27, 2011 @ 17:12
    Sam
    0

    Thanks :) I did gain a certain amount of satisfaction upon page refresh!

    Sam.

  • peterlee 3 posts 20 karma points
    Jul 22, 2013 @ 11:56
    peterlee
    0

    Using code to solve problem is too complicated for me. But I will try the following code to try to get an image from a doctype:

    <?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:outputmethod="xml"indent="yes"omit-xml-declaration="yes"/>

            <xsl:paramname="currentPage"/>
           
            <xsl:templatematch="/">
                    <ulid="listGalleries">
                      <xsl:apply-templatesselect="$currentPage/descendant::* [@isDoc][not(umbracoNaviHide = 1)]"/>
                    </ul>
            </xsl:template>
     
      <xsl:templatematch="* [@isDoc]">
                    <li>
                      <ahref="{umb:NiceUrl(@id)}">
    <xsl:choose>
      <xsl:whentest="galleryThumbnailImage != ''">
        <xsl:variablename="thumb"select="umb:GetMedia(galleryThumbnailImage, false())"/>
        <xsl:variablename="thumbWidth"select="$currentPage/galleryThumbnailWidth"/>
        <imgsrc="/ImageGen.ashx?image={$thumb/umbracoFile}&amp;width={$thumbWidth}"alt="{@nodeName}"/>
      </xsl:when>
    <xsl:otherwise>
      <p>nothing here...</p>
    </xsl:otherwise>
    </xsl:choose>    
                      </a>
                    </li>
            </xsl:template>

    </xsl:stylesheet>

    Thank you for your nice sharing, Sam. As for myself, I used to choose a 3rd party SDK to do with the conversion work whose way of processing is simple and fast according to its tutorials. But I want to learn something about program developing these days. So I will try these code later. THanks again for that. Good luck.

     

     

     

    Best regards,

    Peter

  • peterlee 3 posts 20 karma points
    Jul 22, 2013 @ 12:01
    peterlee
    0

    Using code to solve problem is too complicated for me. But I will try the following code to try to get an image from a doctype:

    <?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:outputmethod="xml"indent="yes"omit-xml-declaration="yes"/>

            <xsl:paramname="currentPage"/>
           
            <xsl:templatematch="/">
                    <ulid="listGalleries">
                      <xsl:apply-templatesselect="$currentPage/descendant::* [@isDoc][not(umbracoNaviHide = 1)]"/>
                    </ul>
            </xsl:template>
     
      <xsl:templatematch="* [@isDoc]">
                    <li>
                      <ahref="{umb:NiceUrl(@id)}">
    <xsl:choose>
      <xsl:whentest="galleryThumbnailImage != ''">
        <xsl:variablename="thumb"select="umb:GetMedia(galleryThumbnailImage, false())"/>
        <xsl:variablename="thumbWidth"select="$currentPage/galleryThumbnailWidth"/>
        <imgsrc="/ImageGen.ashx?image={$thumb/umbracoFile}&amp;width={$thumbWidth}"alt="{@nodeName}"/>
      </xsl:when>
    <xsl:otherwise>
      <p>nothing here...</p>
    </xsl:otherwise>
    </xsl:choose>    
                      </a>
                    </li>
            </xsl:template>

    </xsl:stylesheet>

    Thank you for your nice sharing, Sam. As for myself, I used to choose a 3rd party SDK to do with the conversion work whose way of processing is simple and fast according to its tutorials. But I want to learn something about program developing these days. So I will try these code later. THanks again for that. Good luck.

     

     

     

    Best regards,

    Peter

  • peterlee 3 posts 20 karma points
    Jul 22, 2013 @ 12:04
    peterlee
    0

    Using code to solve problem is too complicated for me. But I will try the following code to try to get an image from a doctype:

    <?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:outputmethod="xml"indent="yes"omit-xml-declaration="yes"/>

            <xsl:paramname="currentPage"/>
           
            <xsl:templatematch="/">
                    <ulid="listGalleries">
                      <xsl:apply-templatesselect="$currentPage/descendant::* [@isDoc][not(umbracoNaviHide = 1)]"/>
                    </ul>
            </xsl:template>
     
      <xsl:templatematch="* [@isDoc]">
                    <li>
                      <ahref="{umb:NiceUrl(@id)}">
    <xsl:choose>
      <xsl:whentest="galleryThumbnailImage != ''">
        <xsl:variablename="thumb"select="umb:GetMedia(galleryThumbnailImage, false())"/>
        <xsl:variablename="thumbWidth"select="$currentPage/galleryThumbnailWidth"/>
        <imgsrc="/ImageGen.ashx?image={$thumb/umbracoFile}&amp;width={$thumbWidth}"alt="{@nodeName}"/>
      </xsl:when>
    <xsl:otherwise>
      <p>nothing here...</p>
    </xsl:otherwise>
    </xsl:choose>    
                      </a>
                    </li>
            </xsl:template>

    </xsl:stylesheet>

    Thank you for your nice sharing, Sam. As for myself, I used to choose a 3rd party SDK to do with the conversion work whose way of processing is simple and fast according to its tutorials. But I want to learn something about program developing these days. So I will try these code later. THanks again for that. Good luck.

     

     

     

    Best regards,

    Peter

Please Sign in or register to post replies

Write your reply to:

Draft