Copied to clipboard

Flag this post as spam?

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


  • Snelbert 13 posts 33 karma points
    Jan 17, 2011 @ 23:59
    Snelbert
    0

    How to select from thousands of documents in media.

    Hello.

    I have uploaded approx 100 technical pdf bulletins into the media section of Umbraco 4.5.2.

    I have a basic 3 column page, each with a WYSIWYG editor allowing the site owner to create pages and enter content, menus, forms and advertisements without needing to know any code.

    I want to create a page that allows the end user to choose and open one of these bulletins.  Initially the plan was to create hyperlinks to each pdf and allow the enduser to select from a drop down list.

    I am not sure this is the way to go though.  It's taken me half my life uploading all those pdfs!

    I appreciate your time if you reply but I really must request you treat me like a moron as I have no clue what I am doing, how to write in xslt..etc etc.  I'm keen to learn though ;-)

    Thank you.

    Snelbert.

  • Snelbert 13 posts 33 karma points
    Jan 18, 2011 @ 00:24
    Snelbert
    0

    Update:  I have managed to write (or copy from some other kind blog post) an XSLT macro that the user can insert in a page and it lists all the documents in that folder.

    Now I need to paginate it or something as the page is very long!

  • Matt Brailsford 4125 posts 22222 karma points MVP 9x c-trib
    Jan 18, 2011 @ 09:48
    Matt Brailsford
    0

    Hey

    Checkout this blog post by Tim on doing pagination in XSLT

    http://www.nibble.be/?p=11

    Matt

  • Snelbert 13 posts 33 karma points
    Jan 18, 2011 @ 16:27
    Snelbert
    0

    Thanks Matt, I wonder if you could offer any more assistance?  I am having problems using this for a media node.  Here is my code.  Can you advise on what I am supposed to put in place of umbraco.library:niceURL? Currently my page is only showing the first 15 items and no next or previous page.

    {umbraco.library:NiceUrl($currentPage/@id)}/{$pageNumber - 1}">previous</a>

    <?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"
      exclude-result-prefixes="msxml umbraco.library">
      <xsl:output method="xml" omit-xml-declaration="yes"/>

      <xsl:param name="currentPage"/>
      <xsl:variable name="documents" select="umbraco.library:GetMedia('1330', 'true')"/>

      <xsl:template match="/">

        <xsl:variable name="recordsPerPage" select="15"/>
        <xsl:variable name="pageNumber">
          <xsl:choose>
            <xsl:when test="umbraco.library:RequestQueryString('page') &lt;= 1 or string(umbraco.library:RequestQueryString('page')) = '' or string(umbraco.library:RequestQueryString('page')) = 'NaN'">1</xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="umbraco.library:RequestQueryString('page')"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <xsl:variable name="numberOfRecords" select="count($currentPage/node)"/>
        
          <xsl:if test="count($documents) > 0">
              <ul>
                <xsl:for-each select="$documents/* [string(data [@alias='umbracoNaviHide']) != '1']">
                  <xsl:if test="position() &gt; $recordsPerPage * number($pageNumber - 1) and position() &lt;= number($recordsPerPage * number($pageNumber - 1) + $recordsPerPage )">
                  <li><a href="{./umbracoFile}" target="_blank"><xsl:value-of select="./@nodeName" /></a></li>
                  </xsl:if>
                  </xsl:for-each>
              </ul>
            </xsl:if>
         
        <xsl:if test="$pageNumber &gt; 1">
          <a href="{./umbracoFile}" target="_blank"><xsl:value-of select="./@nodeName" />($currentPage/@id)}/{$pageNumber - 1}">previous</a>
        </xsl:if>
        <xsl:call-template name="for.loop">
          <xsl:with-param name="i">1</xsl:with-param>
          <xsl:with-param name="page" select="$pageNumber"></xsl:with-param>
          <xsl:with-param name="count" select="ceiling(count($currentPage/node) div $recordsPerPage)"></xsl:with-param>
        </xsl:call-template>
        <xsl:if test="(($pageNumber) * $recordsPerPage) &lt; ($numberOfRecords)">
          <a href="{./umbracoFile}" target="_blank"><xsl:value-of select="./@nodeName" />($currentPage/@id)}/{$pageNumber + 1}">next</a>
        </xsl:if>
      </xsl:template>
      
      <xsl:template name="for.loop">
        <xsl:param name="i"/>
        <xsl:param name="count"/>
        <xsl:param name="page"/>
        <xsl:if test="$i &lt;= $count">
          <xsl:if test="$page != $i">
            <a href="{umbraco.library:NiceUrl($currentPage/@id)}/{$i}" >
              <xsl:value-of select="$i" />
            </a>
          </xsl:if>
          <xsl:if test="$page = $i">
            <xsl:value-of select="$i" />
          </xsl:if>
        </xsl:if>
        <xsl:if test="$i &lt;= $count">
          <xsl:call-template name="for.loop">
            <xsl:with-param name="i">
              <xsl:value-of select="$i + 1"/>
            </xsl:with-param>
            <xsl:with-param name="count">
              <xsl:value-of select="$count"/>
            </xsl:with-param>
            <xsl:with-param name="page">
              <xsl:value-of select="$page"/>
            </xsl:with-param>
          </xsl:call-template>
        </xsl:if>
      </xsl:template>
    </xsl:stylesheet>

  • Matt Brailsford 4125 posts 22222 karma points MVP 9x c-trib
    Jan 18, 2011 @ 16:36
    Matt Brailsford
    0

    Hey,

    I've not checked it fully yet, but the first thing I've spotted is the numberOfRecords variable. It's currently checking for nodes under current page, rather than in your actual media folder, so I think it will want changing to:

    <xsl:variable name="numberOfRecords" select="count($documents/*)"/>

    Give that a try, and see if it helps.

    Matt

  • Snelbert 13 posts 33 karma points
    Jan 18, 2011 @ 16:47
    Snelbert
    0

    Thanks Matt, it certainly does.  I just need to work out how to fix the rest now!

  • Snelbert 13 posts 33 karma points
    Jan 18, 2011 @ 22:18
    Snelbert
    0

    Okay.  I admit it, I know nothing about this!  Please help?

    I can list the first 15 results.  I get a next at the bottom of the page but when I click on it I get page does not exisit error.

    <?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"
      exclude-result-prefixes="msxml umbraco.library">
      <xsl:output method="xml" omit-xml-declaration="yes"/>

      <xsl:param name="currentPage"/>
      <xsl:variable name="documents" select="umbraco.library:GetMedia('1330', 'true')"/>

      <xsl:template match="/">

        <xsl:variable name="recordsPerPage" select="15"/>
        <xsl:variable name="pageNumber">
          <xsl:choose>
            <xsl:when test="umbraco.library:RequestQueryString('page') &lt;= 1 or string(umbraco.library:RequestQueryString('page')) = '' or string(umbraco.library:RequestQueryString('page')) = 'NaN'">1</xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="umbraco.library:RequestQueryString('page')"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <xsl:variable name="numberOfRecords" select="count($documents/*)"/>
        
          <xsl:if test="count($documents) > 0">
              <ul>
                <xsl:for-each select="$documents/* [string(data [@alias='umbracoNaviHide']) != '1']">
                  <xsl:if test="position() &gt; $recordsPerPage * number($pageNumber - 1) and position() &lt;= number($recordsPerPage * number($pageNumber - 1) + $recordsPerPage )">
                  <li><a href="{./umbracoFile}" target="_blank"><xsl:value-of select="./@nodeName" /></a></li>
                  </xsl:if>
                  </xsl:for-each>
              </ul>
            </xsl:if>
         
        <xsl:if test="$pageNumber &gt; 1">
          <a href="{umbraco.library:NiceUrl($currentPage/@id)}/{$pageNumber - 1}">previous</a>
        </xsl:if>
        <xsl:call-template name="for.loop">
          <xsl:with-param name="i">1</xsl:with-param>
          <xsl:with-param name="page" select="$pageNumber"></xsl:with-param>
          <xsl:with-param name="count" select="ceiling(count($currentPage/node) div $recordsPerPage)"></xsl:with-param>
        </xsl:call-template>
        <xsl:if test="(($pageNumber) * $recordsPerPage) &lt; ($numberOfRecords)">
          <a href="{umbraco.library:NiceUrl($currentPage/@id)}/{$pageNumber + 1}">next</a>
        </xsl:if>
      </xsl:template>
      
      <xsl:template name="for.loop">
        <xsl:param name="i"/>
        <xsl:param name="count"/>
        <xsl:param name="page"/>
        <xsl:if test="$i &lt;= $count">
          <xsl:if test="$page != $i">
            <a href="{umbraco.library:NiceUrl($currentPage/@id)}/{$i}" >
              <xsl:value-of select="$i" />
            </a>
          </xsl:if>
          <xsl:if test="$page = $i">
            <xsl:value-of select="$i" />
          </xsl:if>
        </xsl:if>
        <xsl:if test="$i &lt;= $count">
          <xsl:call-template name="for.loop">
            <xsl:with-param name="i">
              <xsl:value-of select="$i + 1"/>
            </xsl:with-param>
            <xsl:with-param name="count">
              <xsl:value-of select="$count"/>
            </xsl:with-param>
            <xsl:with-param name="page">
              <xsl:value-of select="$page"/>
            </xsl:with-param>
          </xsl:call-template>
        </xsl:if>
      </xsl:template>
    </xsl:stylesheet>

  • Matt Brailsford 4125 posts 22222 karma points MVP 9x c-trib
    Jan 19, 2011 @ 09:44
    Matt Brailsford
    0

    Hey,

    Give this a try

    <?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"
      exclude-result-prefixes="msxml umbraco.library">
     
      <xsl:output method="xml" omit-xml-declaration="yes"/>
     
      <xsl:param name="currentPage"/>
     
      <xsl:variable name="documents" select="umbraco.library:GetMedia('1330', 'true')"/>
     
      <xsl:template match="/">
        <xsl:variable name="recordsPerPage" select="15"/>
        <xsl:variable name="pageNumber">
          <xsl:choose>
            <xsl:when test="umbraco.library:RequestQueryString('page') &lt;= 1 or string(umbraco.library:RequestQueryString('page')) = '' or string(umbraco.library:RequestQueryString('page')) = 'NaN'">1</xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="umbraco.library:RequestQueryString('page')"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <xsl:variable name="numberOfRecords" select="count($documents/*)"/>
        <xsl:if test="$numberOfRecords > 0">
          <ul>
            <xsl:for-each select="$documents/*">
              <xsl:if test="position() &gt; $recordsPerPage * number($pageNumber - 1) and position() &lt;= number($recordsPerPage * number($pageNumber - 1) + $recordsPerPage )">
                <li>
                  <a href="{./umbracoFile}" target="_blank">
                    <xsl:value-of select="./@nodeName" />
                  </a>
                </li>
              </xsl:if>
            </xsl:for-each>
          </ul>
        </xsl:if>
     
        <xsl:if test="$pageNumber &gt; 1">
          <a href="{umbraco.library:NiceUrl($currentPage/@id)}?page={$pageNumber - 1}">previous</a>
        </xsl:if>
     
        <xsl:call-template name="for.loop">
          <xsl:with-param name="i">1</xsl:with-param>
          <xsl:with-param name="page" select="$pageNumber"></xsl:with-param>
          <xsl:with-param name="count" select="ceiling($numberOfRecords div $recordsPerPage)"></xsl:with-param>
        </xsl:call-template>
     
        <xsl:if test="(($pageNumber) * $recordsPerPage) &lt; ($numberOfRecords)">
          <a href="{umbraco.library:NiceUrl($currentPage/@id)}?page={$pageNumber + 1}">next</a>
        </xsl:if>
     
      </xsl:template>
     
      <xsl:template name="for.loop">
        <xsl:param name="i"/>
        <xsl:param name="count"/>
        <xsl:param name="page"/>
        <xsl:if test="$i &lt;= $count">
          <xsl:if test="$page != $i">
            <a href="{umbraco.library:NiceUrl($currentPage/@id)}?page={$i}" >
              <xsl:value-of select="$i" />
            </a>
          </xsl:if>
          <xsl:if test="$page = $i">
            <xsl:value-of select="$i" />
          </xsl:if>
        </xsl:if>
        <xsl:if test="$i &lt;= $count">
          <xsl:call-template name="for.loop">
            <xsl:with-param name="i">
              <xsl:value-of select="$i + 1"/>
            </xsl:with-param>
            <xsl:with-param name="count">
              <xsl:value-of select="$count"/>
            </xsl:with-param>
            <xsl:with-param name="page">
              <xsl:value-of select="$page"/>
            </xsl:with-param>
          </xsl:call-template>
        </xsl:if>
      </xsl:template>
     
    </xsl:stylesheet>

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft