Copied to clipboard

Flag this post as spam?

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


  • Brendan Rice 538 posts 1102 karma points
    Oct 01, 2010 @ 01:53
    Brendan Rice
    0

    Repeatable custom contents package question

    I have a page that represents a list of items (quotes) on the page is the above data type that I set up and added two properties to it 'quote' and 'by'.

    As the quotes are shared by all my pages this is why they are in a page seperate from my site (common content folder).

    I have the following XSLT for looping through the quotes on my page. 

    <xsl:value-of select="$quotesPage" />

    The above line returns all the quotes but the loop doesn't loop through each node as it should (according to the developer see his xslt).  Can anyone help please?


      <xsl:param name="currentPage"/>

      <xsl:variable name="minLevel" select="1"/>
      
      <xsl:variable name="quotesPage" select="umbraco.library:GetXmlNodeById('1092')"/>
      
      <!-- Input the repeatable custom contents property alias here -->
      <xsl:variable name="propertyAlias" select="string('quotes')"/>
        
      <xsl:template match="/">
        <xsl:value-of select="$quotesPage" />

        <!-- The fun starts here -->
        <xsl:if test="$quotesPage/data [@alias = $propertyAlias]/items/item">
          <xsl:for-each select="$quotesPage/data [@alias = $propertyAlias]/items/item">
            <h2>Repeatable Custom Content: Item <xsl:value-of select="position()"/> </h2>
            <ul>
              <li>
                Property 1 value: <xsl:value-of select="./data [@alias = 'Quote']" disable-output-escaping="yes"/>
              </li>
              <li>
                Property 2 value: <xsl:value-of select="./data [@alias = 'By']" disable-output-escaping="yes"/>
              </li>
            </ul>
          </xsl:for-each>

          <!-- Live Editing support for related links. -->
        <xsl:value-of select="umbraco.library:Item($currentPage/@id,$propertyAlias,'')" />
       </xsl:if>

      </xsl:template>

     


  • Jonas Eriksson 930 posts 1825 karma points
    Oct 03, 2010 @ 05:51
    Jonas Eriksson
    0

    Hi!

    Just to make sure - your not using 4.52 with new schema are you? In that case you'll need to change that xslt. I think this would do it (but I'm not experienced with the new syntax so I might very well be wrong ...)

    $quotesPage/quotes/items/item

    Whats that "Live Editing support for related links" btw?

    Regards,

    Jonas

    Ps. I'm using repeatable custom content for the same purpose (with legacy schema though).

  • Brendan Rice 538 posts 1102 karma points
    Oct 04, 2010 @ 17:33
    Brendan Rice
    0

    Thanks Jonas, is there any documentation on the new schema?  I didn't even know one existed.

    Here is what I ended up with to get the code working.  What is happening is that I have a list of quotes and show one at random:

    <?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: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:randomTools="http://www.umbraco.org/randomTools"

      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets msxsl randomTools">

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

    <xsl:param name="currentPage"/>

    <xsl:variable name="minLevel" select="1"/>

    <xsl:variable name="quotesPage" select="umbraco.library:GetXmlNodeById('1097')"/>

    <!-- Input the repeatable custom contents property alias here -->
    <xsl:variable name="propertyAlias" select="string('quotes')"/>
       
    <xsl:template match="/">  
      <!-- The fun starts here -->
      <xsl:if test="$quotesPage/quotes/items/item">

        <xsl:variable name="maxItems" select="number(1)" />
        
        <xsl:for-each select="$quotesPage/quotes/items/item">
          <xsl:sort select="randomTools:GetRandom(0,count($quotesPage/quotes/items/item))" order="ascending" />
          <xsl:if test="position() &lt;= $maxItems">
          <blockquote>
              <p><xsl:value-of select="data [@alias = 'quote']" disable-output-escaping="yes"/></p>
          </blockquote>
          <cite> <xsl:value-of select="data [@alias = 'by']" disable-output-escaping="yes"/></cite>

          </xsl:if>
        </xsl:for-each>
        
        <!-- Live Editing support for related links. -->
      <xsl:value-of select="umbraco.library:Item($quotesPage/@id,$propertyAlias,'')" />
     </xsl:if>

    </xsl:template>

      <msxsl:script language="c#" implements-prefix="randomTools">
        <msxsl:assembly href="../bin/umbraco.dll"/>
        <![CDATA[
            /// <summary>
            /// Gets a random integer that falls between the specified limits
            /// </summary>
            /// <param name="lowerLimit">An integer that defines the lower-boundary of the range</param>
            /// <param name="upperLimit">An integer that defines the upper-boundary of the range</param>
            /// <returns>A random integer within the specified range</returns>
            public static int GetRandom(int lowerLimit,int upperLimit) {
                Random r = umbraco.library.GetRandom();
                int returnedNumber = 0;
                lock (r)
                {
                    returnedNumber = r.Next(lowerLimit, upperLimit);
                }
                return returnedNumber;
            }
        ]]>
      </msxsl:script>

        
    </xsl:stylesheet>
Please Sign in or register to post replies

Write your reply to:

Draft