Copied to clipboard

Flag this post as spam?

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


  • syn-rg 282 posts 425 karma points
    May 29, 2012 @ 08:49
    syn-rg
    0

    uComponents multi node tree picker media

    I've created a PDF mediatype. I've added the uComponenets multi node tree picker (MNTP) to my doctype and to link to the PDF folder in my Media section.

    However this is the result I'm getting on the front-end:

    <ul>
    <li><a href=""></a></li>
    <li><a href=""></a></li>
    <li><a href=""></a></li>
    </ul>

    As you can see it's creating the list items but not populating the href or referencing the PDF umbracoFile.

    Can anyone help me with this?

    Cheers, JV

    <?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:msxsl="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library"
      xmlns:synrg="urn:my-scripts"
      exclude-result-prefixes="msxml umbraco.library">
      <xsl:output method="xml" omit-xml-declaration="yes"/>
        
        <xsl:param name="currentPage" />

        <xsl:template match="/">
          
          <xsl:if test="$currentPage/downloads/MultiNodePicker/nodeId">
            <div class="pdf_download_container">
              <ul>
                <xsl:for-each select="$currentPage/downloads/MultiNodePicker/nodeId">
                  <xsl:variable name="node" select="umbraco.library:GetXmlNodeById(.)" />
                  <li>
                    <a href="{./umbracoFile}">
                      <xsl:value-of select="umbracoFile"/>
                    </a>
                    <xsl:if test="umbracoBytes != ''">
                      <span><xsl:value-of select="umbraco.library:FormatDateTime(@updateDate, 'dd MMMM yy')"/><br/>(<xsl:value-of select="synrg:GetFileSize(((umbracoBytes div 1024) div 1024))" />)</span>
                    </xsl:if>
                    <xsl:if test="description != ''">
                      <p><xsl:value-of select="description"/><xsl:if test="readMoreLink != ''">&nbsp;<a href="{umbraco.library:NiceUrl(readMoreLink)}" title="{umbraco.library:GetXmlNodeById(readMoreLink)/@nodeName}">Read more</a></xsl:if></p>
                    </xsl:if>
                  </li>
                </xsl:for-each>
              </ul>
          </div>
      </xsl:if>

    </xsl:template>

        <msxsl:script language="C#" implements-prefix="synrg">
        <![CDATA[public string GetFileSize(Decimal mbs)
          {
          Decimal result = Decimal.Round(mbs, 2);
          if (result == 0)
          {
          result = mbs * 1024;
          return Decimal.Round(result, 2).ToString() + " KB";
          }
          return result.ToString() + " MB";     
          }]]>
        </msxsl:script>
        
    </xsl:stylesheet>
  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    May 29, 2012 @ 22:05
    Chriztian Steinmeier
    1

    Hi JV,

    The reason you're not getting any links is because the picker selects Media items, but you're using GetXmlNodeById() which only returns Content nodes.

    You need to use the GetMedia() extension to find media nodes by id, e.g.:

    <xsl:for-each select="$currentPage/downloads/MultiNodePicker/nodeId">
        <xsl:variable name="node" select="umbraco.library:GetMedia(., false())" />
        <li>
            <a href="{$node/umbracoFile}">
                <xsl:value-of select="$node/umbracoFile"/>
            </a>
            <xsl:if test="normalize-space($node/umbracoBytes)">
                <span>
                    <xsl:value-of select="umbraco.library:FormatDateTime($node/@updateDate, 'dd MMMM yy')"/><br/>(<xsl:value-of select="synrg:GetFileSize((($node/umbracoBytes div 1024) div 1024))" />)
                </span>
            </xsl:if>
            <xsl:if test="normalize-space($node/description)">
                <p>
                    <xsl:value-of select="$node/description"/>
                    <xsl:if test="normalize-space($node/readMoreLink)">
                        <a href="{umbraco.library:NiceUrl($node/readMoreLink)}" title="{umbraco.library:GetXmlNodeById($node/readMoreLink)/@nodeName}">Read more</a>
                    </xsl:if>
                </p>
            </xsl:if>
        </li>
    </xsl:for-each>

    Note that you also need to base all the XPaths within off of the variable you create ($node in your case).

    /Chriztian

    PS: Be sure to read this post from Douglas Robar about converting your <msxsl:script> block into an App_Code extension. 

  • syn-rg 282 posts 425 karma points
    May 30, 2012 @ 02:11
    syn-rg
    0

    Thanks Chriztian,

    I only made one change, I'm using the node name instead of the umbracoFile name:

    <!-- Use this for umbraco file name -->
    <xsl:value-of select="$node/umbracoFile" />

    <!-- Use this for Media node name, if node name is preferred -->
    <xsl:value-of select="$node/@nodeName" />

     

    Also thanks for the link to Douglas Robar's post about converting <msxsl:script> I will be applying this method from now on.

    Cheers, JV

Please Sign in or register to post replies

Write your reply to:

Draft