Copied to clipboard

Flag this post as spam?

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


  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    May 04, 2011 @ 10:56
    Ali Sheikh Taheri
    0

    concatenate variables umbraco 4.7

    Hi,

    I am trying to create a macro that can accept 2 parameters, property name of an image and image cropper type.

    I would liket to concatenate these two to generate an image as follows can anyone tell me what is wrong?

     

    <?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" xmlns:ucomponents.cms="urn:ucomponents.cms" xmlns:ucomponents.dates="urn:ucomponents.dates" xmlns:ucomponents.media="urn:ucomponents.media" xmlns:ucomponents.members="urn:ucomponents.members" xmlns:ucomponents.nodes="urn:ucomponents.nodes" xmlns:ucomponents.search="urn:ucomponents.search" xmlns:ucomponents.strings="urn:ucomponents.strings" xmlns:ucomponents.urls="urn:ucomponents.urls" xmlns:ucomponents.xml="urn:ucomponents.xml" xmlns:ucomponents.io="urn:ucomponents.io" 
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ucomponents.cms ucomponents.dates ucomponents.media ucomponents.members ucomponents.nodes ucomponents.search ucomponents.strings ucomponents.urls ucomponents.xml ucomponents.io ">


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

    <xsl:param name="currentPage"/>
    <xsl:param name="sizeType" select="macro/sizeType" />
    <xsl:param name="imageProperty" select="macro/imageProperty"/>
        
    <xsl:template match="/">
      
      <xsl:variable name="media" select="umbraco.library:GetMedia((concat('$currentPage','/','$imageProperty')),0)" />

      <xsl:if test="$media">
        <xsl:choose>
          <xsl:when test="$sizeType">
            <xsl:variable name="imgSrcCrop" select="concat(substring-before($media/umbracoFile,'.'),'_',$sizeType,'.jpg')" />  
            <img src="{$imgSrcCrop}" alt="{$media/imgAltTxt}"  />
          </xsl:when>
          <xsl:otherwise>
            <img src="{$media/umbracoFile}" alt="{$media/imgAltTxt}"  />
          </xsl:otherwise>
        </xsl:choose>
      </xsl:if>
    </xsl:template>

    </xsl:stylesheet>

    Error occured

    System.OverflowException: Value was either too large or too small for an Int32. 
    at System.Convert.ToInt32(Double value) 
    at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) 
    at System.Xml.Xsl.Runtime.XmlQueryRuntime.ChangeTypeXsltArgument(XmlQueryType xmlType, Object value, Type destinationType) 
    at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args) 
    at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) 
    at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) 
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer) 
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results) 
    at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging

     

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    May 04, 2011 @ 10:59
    Ali Sheikh Taheri
    0

    I tried this too , but still no luck!!!

      <xsl:variable name="media" select="umbraco.library:GetMedia(concat($currentPage,'/',$imageProperty),0)" />

     

  • Pasang Tamang 258 posts 458 karma points
    May 04, 2011 @ 11:30
    Pasang Tamang
    0

    Hi

    I think this line is causing problem for you  <xsl:variable name="media" select="umbraco.library:GetMedia((concat('$currentPage','/','$imageProperty')),0)" />

    just put this line <xsl:if test="$imageProperty&gt;0">

    Thanks

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    May 04, 2011 @ 11:30
    Ali Sheikh Taheri
    0

    what I figured out is I need an DYNAMIC XPATH. like $currentPage/$imageProperty. can anyone help me on this ?

    Thanks

    Ali

     

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    May 04, 2011 @ 11:35
    Ali Sheikh Taheri
    0

    Hi Pasang,

    Thanks for your help, but the imageProperty is not ID of the image ( and I know I can pass ID but I would liket to pass the property name) , it is the property name of the image. like imgHeader

    so what I need is to create a dynamic xpath that can generate $currentPage/imgHeader with something similar to this $currentPage/$imageProperty

    hope that makes sense

    Thanks

    Ali

  • Kim Andersen 1447 posts 2196 karma points MVP
    May 04, 2011 @ 11:41
    Kim Andersen
    1

    Hi Ali

    Maybe this can help you out:

    <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/*[name()=$imageProperty],0)" />

    /Kim A

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    May 04, 2011 @ 11:45
    Ali Sheikh Taheri
    0

    Hi Kim,

    That's exactly what I was looking for. brilliant. 

    You are legend

    Thanks mate.

    Ali

  • Kim Andersen 1447 posts 2196 karma points MVP
    May 04, 2011 @ 11:46
    Kim Andersen
    0

    Cool, great to hear Ali. Glad to help :)

    /Kim A

  • manikandan 7 posts 27 karma points
    May 03, 2012 @ 15:18
    manikandan
    0

    Hi Andersen,

    Actually i am new to umbraco. the same situation came for me please let me know how to solve this. Please find my xsly file below. thanks in advance

    <?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"/>
    <!-- start writing XSLT -->


    <xsl:template match="/">
    <xsl:param name="sourcePaths" select="macro/sourcePath" />
      <xsl:param name="siteimage" select="concat(concat('$currentPage','/',$sourcePaths),'/','imageurl/')" />
    <xsl:variable name="mediaId" select="number($siteimage)" />
    <xsl:if test="$mediaId > 0">
            <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
            <xsl:if test="$mediaNode/umbracoFile">
                <img src="{$mediaNode/umbracoFile}" height="{@umbracoHeight}" width="{@umbracoWidth}" alt="($mediaNode/nodeName)" />

            </xsl:if>
        </xsl:if>  
    </xsl:template>
    </xsl:stylesheet>

Please Sign in or register to post replies

Write your reply to:

Draft