Copied to clipboard

Flag this post as spam?

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


  • Zagros 12 posts 32 karma points
    Dec 23, 2010 @ 14:57
    Zagros
    0

    image

    hi guys,

    I'm trying to get this xslt to print an image tag for me.  This xslt

    <?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:variable name="mediaId" select="/macro/mediaId"/>
    <xsl:variable name="field" select="/macro/field"/>
    <xsl:variable name="media">
    <xsl:choose>
    <xsl:when test="$mediaId = ''">
    <xsl:value-of select="$currentPage[@alias = $field]"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="umbraco.library:GetMedia($mediaId, 'true')"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <xsl:template match="/">

    <textarea> <xsl:copy-of select="$media" /></textarea>

    </xsl:template>



    </xsl:stylesheet>

     

    prints

    <Image id="1069" version="fb862b3f-f9bd-4e0d-9fd8-2ecf5635b277" parentID="1068" level="2" writerID="0" nodeType="1032" template="0" sortOrder="1" createDate="2010-12-18T10:47:11" updateDate="2010-12-18T10:47:12" nodeName="Logo" urlName="logo" writerName="Administrator" nodeTypeAlias="Image" path="-1,1068,1069"><umbracoFile>/media/2/brand_shell.jpg</umbracoFile><umbracoWidth>63</umbracoWidth><umbracoHeight>59</umbracoHeight><umbracoBytes>7163</umbracoBytes><umbracoExtension>jpg</umbracoExtension></Image>

     

    however this xslt gives me error

    <?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:variable name="mediaId" select="/macro/mediaId"/>
    <xsl:variable name="field" select="/macro/field"/>
    <xsl:variable name="media">
    <xsl:choose>
    <xsl:when test="$mediaId = ''">
    <xsl:value-of select="$currentPage[@alias = $field]"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="umbraco.library:GetMedia($mediaId, 'true')"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <xsl:template match="/">

    <xsl:value-of select="$media/umbracoFile" />

    </xsl:template>



    </xsl:stylesheet>

     

     

     

     

     

  • Darren Ferguson 1022 posts 3258 karma points MVP c-trib
    Dec 23, 2010 @ 15:03
    Darren Ferguson
    0

    Post the error....

  • Benjamin Howarth 305 posts 771 karma points c-trib
    Dec 23, 2010 @ 15:05
    Benjamin Howarth
    0

    Zagros,

    +1 to what Darren said, however, I think you need:

    <xsl:value-of select="$media/Image/umbracoFile" />

    HTH,

    Benjamin

  • Zagros 12 posts 32 karma points
    Dec 23, 2010 @ 15:12
    Zagros
    0

    the error is "Unable to parse xslt".  If I attach to IIS and debug I get this error:

    To use a result tree fragment in a path expression, first convert it to a node-set using the msxsl:node-set() function.

     

    I don't think I need that /Image since I tried it and the error didn't go away.

    Plus if I just do this on the page it works:

    <umbraco:Item field="logo" runat="server" xslt="concat('&lt;img src=&quot;', umbraco.library:GetMedia(1069,'true')/umbracoFile, '&quot; /&gt;')" xsltDisableEscaping="true" >

     

     

  • Kim Andersen 1447 posts 2196 karma points MVP
    Dec 23, 2010 @ 15:28
    Kim Andersen
    0

    Hi Zagros

    there's something I don't quite understand here. Let's say that the first when is true (meaning that $mediaId is empty), then you want to show a field from he currentPage called $field right?

    If you are using the new XML schema you should change this:

    <xsl:value-of select="$currentPage/*[name()= $field]"/>

    that's the first thing.

    Now the variable contains the content from that field, then you are using tha content in the value-of.

    <xsl:value-of select="$media/umbracoFile" />

    This will never work.

    Could you say something about what you want to achieve with this code? What can be choosen in the /macro/field? Is this a textstring or what is it?

    I guess that you want to display content from a field on the current page if this is choosen, otherwise you want to render an image. Is that correct?

    /Kim A

  • Zagros 12 posts 32 karma points
    Dec 23, 2010 @ 15:34
    Zagros
    0

    hi Kim,

    I noticed that there's not easy way to print an <img .. /> tag in Umbraco out of box if I have a media already uploaded in the media section of the umbraco admin tool.  So I want to make a Macro that either uses a mediaId if known or uses a media picker value to render an image tag. 

    I'm puzzled why this works and prints the XML in the original post above

    <xsl:copy-of select="$media" />

     

    however I can't do that $media/umbracoFile

     

     

     

  • Kim Andersen 1447 posts 2196 karma points MVP
    Dec 23, 2010 @ 15:41
    Kim Andersen
    0

    So the /macro/field is actually also a media id written directly inside an input field and the /macro/mediaId is a media picker that chooses an image from the media section? Or is it the other way around or something third?

    /Kim A

  • Zagros 12 posts 32 karma points
    Dec 23, 2010 @ 15:43
    Zagros
    0

    hi Kim,

    I noticed that there's not easy way to print an <img .. /> tag in Umbraco out of box if I have a media already uploaded in the media section of the umbraco admin tool.  So I want to make a Macro that either uses a mediaId if known or uses a media picker value to render an image tag. 

    I'm puzzled why this works and prints the XML in the original post above

    <xsl:copy-of select="$media" />

     

    however I can't do that $media/umbracoFile

     

     

     

  • Zagros 12 posts 32 karma points
    Dec 23, 2010 @ 15:45
    Zagros
    0

    yes, that's correct macro field mediaId is a number ..... macro field named 'field' is text.  If I give this macro I'm making media Id, it should use that ... otherwise, use the value of the "field" macro.... this way I can have this generic macro to print me <img .../> tags from the media's people upload.

    again the copy-of results shows that that part works..... it's that one line that is meant to print the umbracoFile which doesn't work

  • Kim Andersen 1447 posts 2196 karma points MVP
    Dec 23, 2010 @ 16:00
    Kim Andersen
    1

    Okay, so actually both of the macros parameters contains media id's?

    If that's the case maybe you can try changing your code to something like this:

    <xsl:variable name="mediaId" select="/macro/mediaId"/>
    <xsl:variable name="field" select="/macro/field"/>
     
    <xsl:variable name="media">
       
    <xsl:choose>
         
    <xsl:when test="$mediaId = ''">
           
    <xsl:value-of select="umbraco.library:GetMedia($mediaId, 1)"/>
         
    </xsl:when>
         
    <xsl:when test="$field = ''>
           
    <xsl:value-of select="umbraco.library:GetMedia($field, 1)"/>
         
    </xsl:when>
       
    </xsl:choose>
     
    </xsl:variable>

     
    <xsl:template match="/">
    <xsl:if test="$media!=''">
         
    <img src="{$media/umbracoFile}" alt="" />
        </xsl:if>
     
    </xsl:template>

    /Kim A

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jan 08, 2011 @ 00:12
    Kim Andersen
    0

    Hi Zagros!

    Did you ever solve this problem. I came to think that you might needed to change the value-of to copy-of in the code that I provided above. But could be nice to know if you ever solved this or you just "forgot" about this issue an found another solution.

    /Kim A

  • 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