Copied to clipboard

Flag this post as spam?

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


  • Brian 77 posts 251 karma points
    Feb 05, 2014 @ 20:37
    Brian
    0

    Referencing Media Items in XLST's - not working

    Hi guys,

    I'm just developing our first website using version 7 and loving it so far, however I seem to be having a slight challenge with regard one of the XSLT's that I have used previously.  Basically it is a list that incorporates images taken from media and selected per page.  The code below was taken from a version 4 site and works fine however when I try to incorporate it into our ver7 site it falls over when saving.

    This is the code I am attempting to use, please note that the ID product has been updated to reflect my ID in the ver 7 site...

     

    <?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:umbraco.contour="urn:umbraco.contour" xmlns:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary" 

      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets umbraco.contour tagsLib BlogLibrary ">

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

    <xsl:param name="currentPage"/>

    <xsl:template match="productImage">

    <img src="{.}"  />

    </xsl:template>

    <xsl:template match="/">

    <!-- The fun starts here -->

      <xsl:for-each select="$currentPage/ProductCategoryList [@isDoc and string(umbracoNaviHide) != '1']">

      <xsl:sort select="@updateDate" order="descending" />

      <div class="newspagearticlehold">

      <div class="portfoliolist">

         <div class="portleft">

        <h2> <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a></h2>

        <div class="portfoliotagsprolist">

                  <ul>

                    <li>Client Name: <span class="space"><xsl:value-of select="clientName"/></span></li>

                    <li>Nature of Project: <span class="space"><xsl:value-of select="natureOfTheProject"/></span></li>

                  </ul>

              </div><!--portfoliotags-->

              <a href="{umbraco.library:NiceUrl(@id)}"><span class="bigredbutton">READ MORE</span></a>

        </div>

        <div class="portfolio

    image">

            <a href="{umbraco.library:NiceUrl(@id)}"><xsl:variable name="media" select="umbraco.library:GetMedia(productImage, 0)"/>

     <xsl:if test="$media">

            <xsl:variable name="url" select="$media/umbracoFile"/>

            <xsl:variable name="width" select="$media/umbracoWidth"/>

            <xsl:variable  name="height" select="$media/umbracoHeight"/>

            <img src="{$url}" width="width" height="height"/>

     </xsl:if>

        </a>

        </div>

        </div>

      </div>

    </xsl:for-each>

     

    </xsl:template>

     

    </xsl:stylesheet>

     

    Cheers for your help guys.

  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    Feb 05, 2014 @ 21:25
    Dennis Aaen
    0

    Hi Brian,

    I have just looked at your code, and one thing I notice is the way you call the GetMedia() in your XSLT.

    Try to change:

     <div class="portfolioimage">

            <a href="{umbraco.library:NiceUrl(@id)}"><xsl:variable name="media" select="umbraco.library:GetMedia(productImage, 0)"/>

             <xsl:if test="$media">

                    <xsl:variable name="url" select="$media/umbracoFile"/>

                    <xsl:variable name="width" select="$media/umbracoWidth"/>

                    <xsl:variable  name="height" select="$media/umbracoHeight"/>

                    <img src="{$url}" width="width" height="height"/>

             </xsl:if>

        </a>
    </div>

    To this:

     <div class="portfolioimage">

            <a href="{umbraco.library:NiceUrl(@id)}">

    <xsl:variable name="media" select="umbraco.library:GetMedia(./productImage, 0)"/>

             <xsl:if test="./productImage !=''">

                    <xsl:variable name="url" select="$media/umbracoFile"/>

                    <xsl:variable name="width" select="$media/umbracoWidth"/>

                    <xsl:variable  name="height" select="$media/umbracoHeight"/>

                    <img src="{$url}" width="{$width}" height="{$height}"/>

             </xsl:if>

        </a>
    </div>

    I hope this will work for you.

    /Dennis

  • Brian 77 posts 251 karma points
    Feb 05, 2014 @ 21:32
    Brian
    0

    Hi Dennis,

     

    Thanks for the advise.  I have just changed the code as suggested and I am getting the same error as before, I have copied the error below:

     

    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.macro.GetXsltTransformResult(XmlDocument macroXml, XslCompiledTransform xslt, Dictionary`2 parameters) at umbraco.presentation.umbraco.developer.Xslt.xsltVisualize.visualizeDo_Click(Object sender, EventArgs e)

     

    To confirm, my code now reads as per below:

     

    <?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:umbraco.contour="urn:umbraco.contour" xmlns:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary" 

      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets umbraco.contour tagsLib BlogLibrary ">

     

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

     

    <xsl:param name="currentPage"/>

    <xsl:template match="productImage">

    <img src="{.}"  />

    </xsl:template>

    <xsl:template match="/">

     

    <!-- The fun starts here -->

      

      <xsl:for-each select="$currentPage/ProductCategoryList [@isDoc and string(umbracoNaviHide) != '1']">

      <xsl:sort select="@updateDate" order="descending" />

      <div class="newspagearticlehold">

      

       

      <div class="portfoliolist">

         <div class="portleft">

        <h2> <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a></h2>

           

          

        

        <div class="portfoliotagsprolist">

                  <ul>

                    <li>Client Name: <span class="space"><xsl:value-of select="clientName"/></span></li>

                    <li>Nature of Project: <span class="space"><xsl:value-of select="natureOfTheProject"/></span></li>

                  </ul>

                 

              </div><!--portfoliotags-->

          

      

        <a href="{umbraco.library:NiceUrl(@id)}"><span class="bigredbutton">READ MORE</span></a>

        </div>

         <div class="portfolioimage">        

    <a href="{umbraco.library:NiceUrl(@id)}">

    <xsl:variable name="media" select="umbraco.library:GetMedia(./productImage, 0)"/>

    <xsl:if test="./productImage !=''">                

    <xsl:variable name="url" select="$media/umbracoFile"/>                

    <xsl:variable name="width" select="$media/umbracoWidth"/>                

    <xsl:variable  name="height" select="$media/umbracoHeight"/>                

    <img src="{$url}" width="{$width}" height="{$height}"/>         

    </xsl:if>    

    </a>

     </div>

        </div>

      </div>

    </xsl:for-each>

     

    </xsl:template>

     

    </xsl:stylesheet>

  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    Feb 05, 2014 @ 22:07
    Dennis Aaen
    101

    Hi Brian,

    Okay then try to change this line:

    <div class="portfolioimage">        

        <a href="{umbraco.library:NiceUrl(@id)}">

            <xsl:variable name="media" select="umbraco.library:GetMedia(./productImage, 0)"/>

                <xsl:if test="./productImage !=''">               

                <xsl:variable name="url" select="$media/umbracoFile"/>               

                <xsl:variable name="width" select="$media/umbracoWidth"/>               

                <xsl:variable  name="height" select="$media/umbracoHeight"/>               

                <img src="{$url}" width="{$width}" height="{$height}"/>        

                </xsl:if>   
        </a>

    </div>

    To this and see if it goes better this time.

    <div class="portfolioimage">       

        <a href="{umbraco.library:NiceUrl(@id)}">

                <xsl:if test="./productImage !=''">

                <xsl:variable name="media" select="umbraco.library:GetMedia(./productImage, 0)"/>           

                <xsl:variable name="url" select="$media/umbracoFile"/>              

                <xsl:variable name="width" select="$media/umbracoWidth"/>              

                <xsl:variable  name="height" select="$media/umbracoHeight"/>              

                <img src="{$url}" width="{$width}" height="{$height}"/>       

                </xsl:if>  
        </a>

    </div>

    Hope this helps,

    /Dennis

  • Brian Milman-Hurst 48 posts 76 karma points
    Feb 06, 2014 @ 08:29
    Brian Milman-Hurst
    0

    Dennis, you are a good man!  that worked fine :)

    I would be really interested to understand why the original code worked on a different website and not on this one, it may also help other fellow XSLT newbies.

     

    Cheers

    Bri

     

  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    Feb 06, 2014 @ 09:01
    Dennis Aaen
    0

    Hi Brian,

    That is great to hear.

    Could you plase mark this as solved, so others can see which code snippet that works. You have a green tick under the name of a author on each comment? That is the mark solution button so should be clicked only on the correct solution.

    /Dennis

  • 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