Copied to clipboard

Flag this post as spam?

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


  • Ed Collins 9 posts 29 karma points
    Aug 03, 2011 @ 14:22
    Ed Collins
    0

    Using XSLT to retrieve ID of a linked file

    I need help on what is probably a simple problem, as I'm new to Umbraco and XSLT.

    The Doc Type of the node has one property that will link to a file using the Media Picker, in this case a PDF file. My goal is to set up child nodes using this docuement type and have the parent node read all of the children and list the values. That part I can do easily enough. The problem is when trying to create a URL that will link to the PDF file resource.I am able to pull the ID for the PDF (1533) but cannot build the URL in my XSLT without an error. (Hopefully my explanation is clear.)

    Here is the code as I have it now. There are several lines at the bottom that I'm using for testing/debug. Thanks for any help.

    <?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:PS.XSLTsearch="urn:PS.XSLTsearch"
        exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets umbraco.contour PS.XSLTsearch ">

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

    <xsl:param name="currentPage"/>
    <xsl:variable name="productResourceLink">
        <xsl:value-of select="$currentPage/data[@alias='productResourceLink']"/>
    </xsl:variable>

    <xsl:template match="/">

    <!-- The fun starts here  -->

    <ul>
    <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) = '1']">
        <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="@nodeName"/>
            </a>
        </li>
        <li>
            Category: <xsl:value-of select="productResourceCategory"/>
        </li>
        <li>
            Desc: <xsl:value-of select="productResourceDescription"/>
        </li>
        <li>
            Link: <a href="{@id}">
                <xsl:value-of select="@nodeName"/>
            </a>
        </li>
        <li>
            Name: <xsl:value-of select="productResourceName"/>
        </li>
        <li>
            productResourceLink: <xsl:value-of select="productResourceLink"/>
        </li>
    <li>

    <!-- testing code below, without success -->
    <br />
    <xsl:if test="$productResourceLink = $currentPage/data[@alias='productResourceLink'] ">   
            <!-- these two values are not equal.
            When the if statement is removed, the following error is shown:
            System.OverflowException: Value was either too large or too small for an Int32. -->
    <xsl:value-of select="umbraco.library:NiceUrl($currentPage/data[@alias='productResourceLink'])/number" />
    Testing Link: <a href="{umbraco.library:NiceUrl($currentPage/data[@alias='productResourceLink'])/data [@alias = 'productResourceLink']}" target="_blank">View PDF</a>
    </xsl:if>
       
    <br />
    resourceID: <xsl:value-of select="productResourceLink"/>
        <!-- this displays the correct ID of 1533 in the browser -->
    <br />
    Working Link: <a href="{umbraco.library:GetMedia('1533',0)/umbracoFile}" target="_blank">View PDF</a>
    <!-- this works and links to the file in child node, but the ID is hard coded -->

    </li>

    </xsl:for-each>

    </ul>

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

  • John 27 posts 49 karma points
    Aug 03, 2011 @ 15:42
    John
    0

    Hi would you not use ?

     

     <a href="{umbraco.library:GetMedia(productResourceLink,0)/umbracoFile}" target="_blank">View PDF</a>
  • Ed Collins 9 posts 29 karma points
    Aug 03, 2011 @ 15:50
    Ed Collins
    0

    John,

    Thanks very much for your help.

    That solution works if I check the "Skip testing" option.

    But, if I allow testing, then this error will show "System.OverflowException: Value was either too large or too small for an Int32."

    Any idea what's causing that error?

  • John 27 posts 49 karma points
    Aug 03, 2011 @ 16:22
    John
    0

    Perhaps one of you nodes doesn't have a productResourceLink try:


    <xsl:if test="productResourceLink&gt;0">

    <ahref="{umbraco.library:GetMedia(productResourceLink,0)/umbracoFile}"target="_blank">View PDF</a>

    </xsl:if>





  • Ed Collins 9 posts 29 karma points
    Aug 03, 2011 @ 16:35
    Ed Collins
    0

    John,

    There is only one node right now, at least that is visible in the Content tree. I've created other nodes and deleted them. I tried adding the if statement, but still the same error. I'll ask the server admin to check and see if there is a node that isn't visible in Umbraco. Perhaps that is the problem.

    Thanks again for your help.

Please Sign in or register to post replies

Write your reply to:

Draft