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 21, 2012 @ 09:24
    syn-rg
    0

    Related media populating on pages - uComponents Multi-Node Tree Picker

    I've created a media type "PDF" and I have added a datatype "relatedPages" (uComponents Mutli-Node Tree picker).

    I want to be able to link the uploaded PDF to relevant pages through out the website. Then have those PDF's available to download on the relevant pages.

    What would be the best method for achieving this?
    Cheers, JV

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


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

      <xsl:param name="currentPage"/>
      
      <!-- Input the related links property alias here -->
      <xsl:variable name="propertyAlias" select="string('relatedPages')"/>
      

        <xsl:template match="/">

      <!--
        uComponents: Multi-node Tree Picker - An XSLT example
        =====================================
        The Multi-node Tree Picker data-type will provide XML data based on the nodes you have selected.
        In this example, the property alias name for the Multi-node Tree Picker is "treePicker".
      -->

      <!-- First we check that the Multi-node Tree Picker has any nodeId values -->
      <xsl:if test="$currentPage/relatedPages/MultiNodePicker/nodeId">

        <div class="pdf_download_container">
            <ul>

          <!-- Loop through each of the nodeId values -->
          <xsl:for-each select="$currentPage/relatedPages/MultiNodePicker/nodeId">

            <!-- Since we only have the nodeId value, we need to get the actual content node using umbraco.library's GetXmlNodeById method -->
            <!-- If you prefer to use pure XPath, then used this: "$currentPage/ancestor-or-self::*[@isDoc and @level = 1]/descendant-or-self::*[@isDoc and @id = current()]" -->
            <xsl:variable name="node" select="umbraco.library:GetXmlNodeById(.)" />

            <li>

              <!-- Output the URL using umbraco.library's NiceUrl method -->
              <p><a href="{umbraco.library:NiceUrl(.)}">

                <xsl:value-of select="$node/@nodeName" />

              </a></p>

            </li>

          </xsl:for-each>

        </ul>
          </div>
      </xsl:if>

    </xsl:template>

    </xsl:stylesheet>
  • syn-rg 282 posts 425 karma points
    May 22, 2012 @ 09:07
    syn-rg
    0

    I've got the PDF media type displaying in the list now, but I need the list to only appear if a PDF has been assigned to that page. And only the PDF's assigned to that page should appear.

    The media type "PDF" has a datatype "relatedPages" (uComponents Mutli-Node Tree picker). This is used to pick the pages that the PDF should appear on.

    Here's my current 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: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:param name="mediafolder" select="/macro/mediaFolder/Folder/@id" />
        
        <xsl:template match="/">
          <!--<p><b>mediaFolder:</b> <xsl:value-of select="$mediafolder" /></p>-->
          
          <xsl:if test="$mediafolder !=''">
            <xsl:variable name="files" select="umbraco.library:GetMedia($mediafolder, true())" />
            <xsl:variable name="propertyAlias" select="string('relatedPages')"/>
            
            <!-- Uncomment this for DEBUG and view the HTML source of your page to see the XML snippet -->
            <!-- <xsl:copy-of select="$files" /> -->
            
            <xsl:if test="$files != ''">
              <div class="pdf_download_container">
                <ul>
                  <!-- For each XML node <node> where the nodeTypeAlias attribute = File -->
                  <xsl:for-each select="$files/PDF[@nodeTypeAlias = 'PDF']">
                    <li>
                      <!-- On the current XML node <node> find the XML node <data> where the alias atribute = umbracoFile -->
                      <!-- This is where the filepath to the file is stored -->
                      <a href="{./umbracoFile}" class="external">
                        <xsl:value-of select="@nodeName" />
                      </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: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>

     

    Here's the XSLT I use to display Related links "relatedLinks" I'm trying to figure out what elements of this I can use for my PDF 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" xmlns:PS.XSLTsearch="urn:PS.XSLTsearch"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets PS.XSLTsearch ">


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

      <xsl:param name="currentPage"/>
      
      <!-- Input the related links property alias here -->
      <xsl:variable name="propertyAlias" select="string('relatedLinks')"/>
      

        <xsl:template match="/">

      <!--
        uComponents: Multi-node Tree Picker - An XSLT example
        =====================================
        The Multi-node Tree Picker data-type will provide XML data based on the nodes you have selected.
        In this example, the property alias name for the Multi-node Tree Picker is "treePicker".
      -->

      <!-- First we check that the Multi-node Tree Picker has any nodeId values -->
      <xsl:if test="$currentPage/relatedLinks/MultiNodePicker/nodeId">

        <div class="related_links_container">
            <h1>Related Links</h1>
            <ul>

          <!-- Loop through each of the nodeId values -->
          <xsl:for-each select="$currentPage/relatedLinks/MultiNodePicker/nodeId">

            <!-- Since we only have the nodeId value, we need to get the actual content node using umbraco.library's GetXmlNodeById method -->
            <!-- If you prefer to use pure XPath, then used this: "$currentPage/ancestor-or-self::*[@isDoc and @level = 1]/descendant-or-self::*[@isDoc and @id = current()]" -->
            <xsl:variable name="node" select="umbraco.library:GetXmlNodeById(.)" />

            <li>

              <!-- Output the URL using umbraco.library's NiceUrl method -->
              <p><a href="{umbraco.library:NiceUrl(.)}">

                <xsl:value-of select="$node/@nodeName" />

              </a></p>

            </li>

          </xsl:for-each>

        </ul>
          </div>
      </xsl:if>

    </xsl:template>

    </xsl:stylesheet>
  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    May 22, 2012 @ 12:52
  • syn-rg 282 posts 425 karma points
    May 22, 2012 @ 15:30
    syn-rg
    0

    Thanks Jeroen, but I don't think that will work for what I want.

    I'm still no closer with this, but I figure it's just a matter of filtering the "relatedPages" into the "files" variable. So that it will only display on the page if a "relatedPages" value is attached it.

    Latest 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: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:param name="mediafolder" select="/macro/mediaFolder/Folder/@id" />
        
        <xsl:template match="/">
          <!--<p><b>mediaFolder:</b> <xsl:value-of select="$mediafolder" /></p>-->
          
          <xsl:if test="$mediafolder !=''">
            <!--<xsl:variable name="propertyAlias" select="string('relatedPages')"/>
            <xsl:variable name="files" select="umbraco.library:GetMedia($mediafolder, true())/descendant-or-self::* [@nodeTypeAlias and string(relatedPages) != '1']" />-->
            <xsl:variable name="files" select="umbraco.library:GetMedia($mediafolder, true())" />
            
            <!--<xsl:variable name="possibleNodes" select="umbraco.library:GetMedia(1315, 'true')/descendant-or-self::* [@isDoc]" />-->
            
            <!-- Uncomment this for DEBUG and view the HTML source of your page to see the XML snippet -->
             <!--<xsl:copy-of select="$files" /> -->
            
            <xsl:if test="$files != ''">
              <div class="pdf_download_container">
                <ul>
                  <!-- For each XML node <node> where the nodeTypeAlias attribute = File -->
                  <xsl:for-each select="$files/PDF[@nodeTypeAlias = 'PDF']">
                    <li>
                      <!-- On the current XML node <node> find the XML node <data> where the alias atribute = umbracoFile -->
                      <!-- This is where the filepath to the file is stored -->
                      <a href="{./umbracoFile}" class="external">
                        <xsl:value-of select="@nodeName" />
                      </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: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>
  • syn-rg 282 posts 425 karma points
    May 28, 2012 @ 02:16
    syn-rg
    0

    SOLVED!

    Here's the final code:

    <?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:param name="mediafolder" select="/macro/mediaFolder/Folder/@id" />
        
        <xsl:template match="/">
          
          <xsl:if test="$mediafolder !=''">
            <xsl:variable name="files" select="umbraco.library:GetMedia($mediafolder, true())/descendant-or-self::*[nodeId =  $currentPage/@id]/parent::*/parent::*" />
            <xsl:if test="$files != ''">
              <div class="pdf_download_container">
                <ul>
                  <xsl:for-each select="$files">
                    <li>
                      <a href="{./umbracoFile}" class="external">
                        <xsl:value-of select="@nodeName" />
                      </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: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>
Please Sign in or register to post replies

Write your reply to:

Draft