Copied to clipboard

Flag this post as spam?

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


  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jun 02, 2010 @ 13:55
    Jeroen Breuer
    0

    Set variable in foreach and use it outside the foreach

    Hello,

    I'm writing an XSLT file in which I need to set a variable. This variable can be fetched from a querystring. If the value is empty it needs to be set at a later moment. In a foreach loop I need to get the first value if the querystring is empty. After this I need the value outside of the foreach loop. I can't figure out how to do this since a variable can only be set once (or only used inside the foreach loop). Any idea's how to solve this?

    Jeroen

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 02, 2010 @ 14:03
    Matt Brailsford
    1

    Hi Jeroren,

    I think you are going to have to do the foreach within the variable element

    <xsl:variable name="myVar">


    <xsl:choose>
    <xsl:when test="string-length(umbraco.library:RequestQueryString('myVar')) &gt; 0">
    <xsl:value-of select="umbraco.library:RequestQueryString('myVar')" />
    </xsl:when>
    <xsl:otherwise>

    <xsl:for-each select="...">
    ...
    </xsl:for-each>
    </xsl:otherwise>
    </xsl:variable>

    Many thanks

    Matt

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 02, 2010 @ 14:04
    Matt Brailsford
    0

    If the for-each is semi intensive, it might be worth doing the for-each and storing the result in it's own variable first, then do 2 less intensive for-each loops, one inside the variable definition, and one in the body.

    Many thanks

    Matt

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jun 02, 2010 @ 14:07
    Jeroen Breuer
    0

    Hi Matt,

    That would be a solution. I might be able to solve it with an Xpath statement, but the foreach loop also has pages (and I need the first Id of loaded page) so I would need to do that inside the Xpath. In the loop I'm also calling templates so I would need to loop twice because I can't do it at the same time.

    Jeroen

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 02, 2010 @ 14:09
    Matt Brailsford
    0

    Hey Jeroen,

    Not sure what you mean by "Pages", but maybe if you posted an example peice of XML, we could write a XPath statemnt that avoids a for-each?

    Matt

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jun 02, 2010 @ 14:19
    Jeroen Breuer
    0

    Hi Matt,

    Well it's got to do with the XSLT jQuey paging sample you helped me with :). I need to get the id of the first row displayed in a page. So if the page is 2 I need id of the first row displayed. Here is some code:

    <!-- The nodes which will be displayed. -->
      <xsl:variable name="nodes" select="$currentPage/node [@nodeTypeAlias = 'NewsItem']" />
     <!-- Get the newsId from the querystring. If it's empty get the first id from the displayed page. -->
      <xsl:variable name="newsId" >
        <xsl:choose>
          <xsl:when test="umbraco.library:RequestQueryString('newsId') &lt;= 0 or string(umbraco.library:RequestQueryString('newsId')) = '' or string(number(umbraco.library:RequestQueryString('newsId'))) = 'NaN'">
            <!-- This XPath needs to be updated -->
            <xsl:value-of select="$nodes[2]/@id" />
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="umbraco.library:RequestQueryString('newsId')"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
    <!-- Loop through items ordered by date descending. -->
              <xsl:for-each select="$nodes">
              <xsl:sort order="descending" select="data[@alias = 'date']" data-type="text"/>
              <xsl:sort order="descending" select="@createDate" data-type="text"/>
              <xsl:if test="position() &gt; ($itemsPerPage * $pageIndex) and position() &lt;= number(($itemsPerPage * $pageIndex) + $itemsPerPage)">
    
                <!-- Show the news item. -->
                <xsl:call-template name="create-news-item">
                  <xsl:with-param name="node" select="." />
                </xsl:call-template>
    
              </xsl:if>
              </xsl:for-each>

    Hope you can help me with an XPath.

    Jeroen

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 02, 2010 @ 14:35
    Matt Brailsford
    0

    Hey Jeroen,

    Maybe try this as the selector:

    <xsl:value-of select="$nodes[$itemsPerPage * $pageIndex]/@id" />

    That should get the first node for the given page (so long as you have done all the paging stuff before hand obviously)

    Matt

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jun 02, 2010 @ 14:44
    Jeroen Breuer
    0

    Hi Matt,

    That alsmost worked. Now it's this:

    <xsl:value-of select="number($nodes[($itemsPerPage * $pageIndex)+1]/@id)" />

    This works, but as you might have noticed the foreach uses a sort so I get back a value but it's not the correct value because I need the same sorting on the XPath. Any idea how that's possible?

    Jeroen

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 02, 2010 @ 15:02
    Matt Brailsford
    1

    Lol, i wasn't sure wheather it needed plus 1 =)

    Ok, maybe for your nodes, try this

    <xsl:variable name="nodes">
      <xsl:for-each select="$currentPage/node [@nodeTypeAlias = 'NewsItem']">
        <xsl:sort order="descending" select="data[@alias = 'date']" data-type="text"/>
        
    <xsl:sort order="descending" select="@createDate" data-type="text"/>
        <xsl:copy-of select="." />
      </xsl:for-each>
    </xsl:varaible>

    Not sure whether you will then need to use the node-set() method to convert it back into a nodeset or not, but you can give it a try.

    But you should then be able to skip the sorting in the body.

    Matt

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Jun 02, 2010 @ 15:15
    Peter Duncanson
    0

    Yep thats the way to go, sort your nodes first and store the sorted nodes in a variable. Then you can use you xpath on the sorted nodes in the variable.

    Like mate says you "may" need to use msxml:node-set( $nodes ) to convert to a node-set. I never remember the rule for when to do this so tend to try it out first. Really should read up on the whys and wheres for node-set function usage.

    Good fix Matt, gets my vote!

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jun 02, 2010 @ 15:26
    Jeroen Breuer
    0

    Hi Matt,

    Is it possible the values are stored differently in the variable now? Your code works, but after this I try a count and this throws an error.

    <!-- The total amount of items -->
      <xsl:variable name="totalItems" select="count($nodes)" />

    This used to work, but now it doesn't. It just throws an error and I don't know what's going wrong. Thanks for all the help so far.

    Jeroen

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 02, 2010 @ 15:34
    Matt Brailsford
    0

    Yea, thats when the node-set method comes in, try:

     <xsl:variable name="totalItems" select="count(msxml:node-set$nodes))" />

    Matt

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Jun 02, 2010 @ 15:34
    Peter Duncanson
    0

    Error message?

    Could be the node-set issue. When you sort XML in a variable it needs to be stored as a "node-set" if you want to do anything useful with it. Luckily MS gives us a way to convert our XML fragments into node sets using the node-set function. So you could do:

    <xsl:variable name="totalItems" select="count( msxml:node-set( $nodes ) )" />

    Can get a bit messy so I tend to convert it once, first build you variable up using a temp variable then convert that once into your real variable:

    <xsl:variable name="temp_nodes" select="DO SOMETHING HERE TO GET MY NODES" />
    <xsl:variable name="nodes" select="msxml:node-set( temp_nodes )" />
    <xsl:variable name="totalItems" select="count( $nodes )" />

    That should do it and its much clear to read too.

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 02, 2010 @ 15:34
    Matt Brailsford
    0

    Ooops, missed a braket 

    <xsl:variable name="totalItems" select="count(msxml:node-set($nodes))" />

    Matt

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 02, 2010 @ 15:38
    Matt Brailsford
    0

    Good idea Pete, putting into a temp var first and only doing the cast once.

    Matt

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 02, 2010 @ 15:39
    Matt Brailsford
    1

    PS, you missed a dolar sign in your temp var reference

    <xsl:variable name="nodes" select="msxml:node-set( $temp_nodes )" />

    Matt

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jun 02, 2010 @ 16:01
    Jeroen Breuer
    0

    Thanks for all the great replies. This is all pretty new to me and I'm still getting errors. Now I get the following error if I try

    <xsl:variable name="nodes" select="msxml:node-set( $temp_nodes )" />

    msxml:node-set($temp_nodes) The function msxml:node-set() is not defined

    Do I need to include something extra?

    Jeroen

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 02, 2010 @ 16:18
    Matt Brailsford
    0

    Hey Jeroen,

    Make sure you have the following in your xslt:stylesheet declaration:

    xmlns:msxml="urn:schemas-microsoft-com:xslt"

    Also make sure you add msxml to the exclude-result-prefixes attribute too

    Matt

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jun 02, 2010 @ 16:22
    Jeroen Breuer
    0

    Hi Matt,

    I think I already did this. Here is the top of 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" 
        exclude-result-prefixes="msxml umbraco.library  Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
    
    <xsl:import href="Include.LibraryExt.xslt" />
    
    <xsl:output method="html" omit-xml-declaration="yes"/>
    
    <xsl:param name="currentPage"/>

    Jeroen

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 02, 2010 @ 16:40
    Matt Brailsford
    0

    Hmmm, that is weird, and you are calling msxml:node-set(...) within that XSLT file and not the include?

    Matt

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jun 02, 2010 @ 16:51
    Jeroen Breuer
    0

    I'm calling from withing the file. Here is my entire 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" 
        exclude-result-prefixes="msxml umbraco.library  Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
    
    <xsl:import href="Include.LibraryExt.xslt" />
    
    <xsl:output method="html" omit-xml-declaration="yes"/>
    
    <xsl:param name="currentPage"/>
    
      <!-- This variable is set in the macro. It determines the max lenght of the summary. -->
      <xsl:variable name="maxSummaryLength">
        <xsl:choose>
          <xsl:when test="/macro/maxSummaryLength">
            <xsl:value-of select="/macro/maxSummaryLength"/>
          </xsl:when>
          <xsl:otherwise>100</xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
    
      <!-- This variable is set in the macro. It determines the number of items per page. -->
      <xsl:variable name="itemsPerPage">
        <xsl:choose>
          <xsl:when test="umbraco.library:RequestQueryString('page') = 'all'">
            <xsl:value-of select="$totalItems" />
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="/macro/itemsPerPage" />
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
    
          <!-- This is the test code which goes wrong. -->
          <xsl:variable name="nodes2">
            <xsl:for-each select="$currentPage/node [@nodeTypeAlias = 'NewsItem']">
              <xsl:sort order="descending" select="data[@alias = 'date']" data-type="text"/>
              <xsl:sort order="descending" select="@createDate" data-type="text"/>
              <xsl:copy-of select="." />
            </xsl:for-each>
          </xsl:variable>
    
          <!--Convert doesn't work. nodes3 is empty afterwards-->
          <xsl:variable name="nodes3" select="msxml:node-set($nodes2)" />
    
          <!-- This is where the exception occurs because nodes3 is empty. -->
          <xsl:variable name="totalItemsTest" select="count(nodes3)" />
    
      <!-- Continue with the unsorted version. -->
      <xsl:variable name="nodes" select="$currentPage/node [@nodeTypeAlias = 'NewsItem']" />
    
      <!-- The total amount of items -->
      <xsl:variable name="totalItems" select="count($nodes)" />
    
      <!-- Determine which page needs to be displayed. -->
      <xsl:variable name="page" >
        <xsl:choose>
          <xsl:when test="umbraco.library:RequestQueryString('page') &lt;= 0 or string(umbraco.library:RequestQueryString('page')) = '' or string(number(umbraco.library:RequestQueryString('page'))) = 'NaN'">
            <xsl:value-of select="1" />
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="number(umbraco.library:RequestQueryString('page'))"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:variable name="pageIndex" select="$page - 1" />
    
      <!-- Get the newsId from the querystring. If it's empty get the first id from the displayed page. -->
      <xsl:variable name="newsId">
        <xsl:choose>
          <xsl:when test="umbraco.library:RequestQueryString('newsId') &lt;= 0 or string(umbraco.library:RequestQueryString('newsId')) = '' or string(number(umbraco.library:RequestQueryString('newsId'))) = 'NaN'">
            <xsl:value-of select="number($nodes[($itemsPerPage * $pageIndex)+1]/@id)" />
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="number(umbraco.library:RequestQueryString('newsId'))"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
    
      <!-- Start rendering. -->
      <xsl:template match="/">
        <xsl:choose>
          <xsl:when test="$totalItems &gt; 0">
    
            <div class="sidebar long">
              <h2>Nieuws</h2>
    
              <!-- Loop through items ordered by date descending. -->
              <xsl:for-each select="$nodes">
              <xsl:if test="position() &gt; ($itemsPerPage * $pageIndex) and position() &lt;= number(($itemsPerPage * $pageIndex) + $itemsPerPage)">
    
                <!-- Show the news item. -->
                <xsl:call-template name="create-news-item">
                  <xsl:with-param name="node" select="." />
                </xsl:call-template>
    
              </xsl:if>
              </xsl:for-each>
    
              <div class="divider"></div>
    
              <!-- Show the pager. -->
              <xsl:call-template name="create-pager">
                <xsl:with-param name="itemsPerPage" select="$itemsPerPage" />
                <xsl:with-param name="totalItems" select="$totalItems" />
                <xsl:with-param name="currentPage" select="$page" />
                <xsl:with-param name="showNumbers" select="0" />
                <xsl:with-param name="showViewAll" select="0" />
              </xsl:call-template>
            </div>
    
            <div class="mainContent">
    
              <xsl:variable name="newsNode" select="umbraco.library:GetXmlNodeById($newsId)" />
    
              <h2>
                <xsl:value-of select="$newsNode/data[@alias = 'pageTitle']"/>
              </h2>
              <xsl:value-of select="$newsNode/data[@alias = 'bodyText']" disable-output-escaping="yes"/>
            </div>
    
          </xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="no-results" />
          </xsl:otherwise>
        </xsl:choose>
    
      </xsl:template>
    
      <!-- This template renders a news item. -->
      <xsl:template name="create-news-item">
        <xsl:param name="node"/>
    
          <!-- Determine which item needs to be active. -->
          <xsl:variable name="selected">
            <xsl:choose>
              <xsl:when test="@id = $newsId"> active</xsl:when>
              <xsl:otherwise></xsl:otherwise>
            </xsl:choose>
          </xsl:variable>
    
          <!-- Display a link to the node. -->
          <a href="{concat(umbraco.library:NiceUrl($currentPage/@id), '?page=', $page, '&amp;newsId=', @id)}" class="{concat('navItem nieuws', $selected)}">
            <p>
              <img src="/images/nieuwsX.jpg" width="65" height="65" border="0" class="masked65" align="left" />12 mei 2010
            </p>
            <p class="item">
              <xsl:value-of select="data[@alias = 'pageTitle']"/>
            </p>
          </a>
          <div class="divider"></div>
    
      </xsl:template>
    
      <!-- This template renders a message if no results are found. -->
      <xsl:template name="no-results">
        <div>
          <h3>Geen nieuws items gevonden</h3>
        </div>
      </xsl:template>
    
    </xsl:stylesheet>

    I don't know what's going wrong.

    Jeroen

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 02, 2010 @ 16:59
    Matt Brailsford
    0

    count(nodes3) needs to be count($nodes3) but not sure whether that would throw the exception you mentioned

    Matt

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jun 02, 2010 @ 17:13
    Jeroen Breuer
    0

    Hi Matt,

    That was a typo. Unfortunately it doesn't solve my problem. I still get the same error. It's not defind and because of that none of the results returned are properly.

    <xsl:variable name="totalItemsTest" select="count(msxml:node-set($nodes2))" />

    This returns 1 because the code doens't work and somehow I get a 1 back. If I debug count(msxml:node-set($nodes2)) I get an exception but the variable gets set to 1. Any suggestions?

    Jeroen

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 02, 2010 @ 17:20
    Matt Brailsford
    0

    Hmmmm, really not sure on that one then. Could do with knowing more about the exception.

    What version of .NET are you using? Not that I'm aware of any versioning issues.

    Matt

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jun 02, 2010 @ 17:36
    Jeroen Breuer
    0

    I'm using .NET 3.5 and the only thing the exception show is 'The function msxml:node-set() is not defined'.

    Here are some debug images with info:

    1 execute the following code

    <xsl:variable name="nodes2">
        <xsl:for-each select="$currentPage/node [@nodeTypeAlias = 'NewsItem']">
          <xsl:copy-of select="." />
        </xsl:for-each>
      </xsl:variable>

    2 Result in the debugger: http://img9.imageshack.us/f/77430599.jpg/

    3 Try to do the conversion: 

    <xsl:variable name="nodes3" select="msxml:node-set($nodes2)" />

    4 Watching the select in the debugger: http://img241.imageshack.us/f/45058934.jpg/

    So that's what's happening. If I can't get this solved I'll go with the first idea you had Matt. I'll set the id inside the variable.

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jun 02, 2010 @ 19:53
    Jeroen Breuer
    0

    Well I don't know what goes wrong so I used Matt his example. Here is the code:

    <!-- Get the newsId from the querystring. If it's empty get the first id from the displayed page. -->
      <!-- This code could be better because now we loop twice through the loops. -->
      <xsl:variable name="newsId">
        <xsl:choose>
          <xsl:when test="umbraco.library:RequestQueryString('newsId') &lt;= 0 or string(umbraco.library:RequestQueryString('newsId')) = '' or string(number(umbraco.library:RequestQueryString('newsId'))) = 'NaN'">
            <xsl:for-each select="$nodes">
              <xsl:sort order="descending" select="data[@alias = 'date']" data-type="text"/>
              <xsl:sort order="descending" select="@createDate" data-type="text"/>
              <xsl:if test="position() &gt; ($itemsPerPage * $pageIndex) and position() &lt;= number(($itemsPerPage * $pageIndex) + $itemsPerPage)">
                <xsl:if test="position() = ($itemsPerPage * ($pageIndex)+1)">
                  <xsl:value-of select="@id"/>
                </xsl:if>
              </xsl:if>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="number(umbraco.library:RequestQueryString('newsId'))"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>

    Too bad I couldn't solve it properly, but I'm out of time and this works for now.

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jun 03, 2010 @ 08:37
    Jeroen Breuer
    0

    I got it solved! After looking at a sample my colleague used I discovered what I was missing.

    Here is how it's done:

      <!-- The nodes which will be displayed. Sorted in the correct order. -->
      <xsl:variable name="temp_nodes">
        <xsl:for-each select="$currentPage/node [@nodeTypeAlias = 'NewsItem']">
          <xsl:sort order="descending" select="data[@alias = 'date']" data-type="text"/>
          <xsl:sort order="descending" select="@createDate" data-type="text"/>
          <xsl:copy-of select="." />
        </xsl:for-each>
      </xsl:variable>
    
      <!-- Convert the nodes to a which is easier to work with. -->
      <xsl:variable name="nodes" select="msxml:node-set($temp_nodes)/node" />
    
      <!-- The total amount of items -->
      <xsl:variable name="totalItems" select="count($nodes)" />

    I was missing the /node after the msxml:node-set. Strange enough if you try to look at the value in the debugger you get an error like in the screens I posted earlier. Despite you can't look at the value in the debugger the code still works. This solved my problem :).

    Jeroen

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 03, 2010 @ 09:18
    Matt Brailsford
    0

    Thats strange, but hey, glad you managed to get it working.

    Matt

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 03, 2010 @ 11:20
    Matt Brailsford
    0

    Hey Jeroen,

    You may want to think about marking a post as an answer, as the topic got pretty long =)

    Matt

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jul 08, 2010 @ 14:06
    Jeroen Breuer
    0

    I'd like to kick this topic again :). 3 posts up is how I solved my problem, but this solution doens't work in Umbraco 4.5. How can I do the following in 4.5?

    <!-- Convert the nodes to a way which is easier to work with. -->
    <xsl:variable name="nodes" select="msxml:node-set($temp_nodes)/node" />

    The /node doesn't work anymore since each element has a new name. How should this be done in 4.5?

    Jeroen

  • Tommy Poulsen 514 posts 708 karma points
    Jul 08, 2010 @ 14:17
    Tommy Poulsen
    2

    You no longer have generic nodes called "node", so you have to provide either the nodename (i.e. the old alias) instead, or a wildcard char, e.g. '*'

    e.g.

    <xsl:variable name="nodes" select="msxml:node-set($temp_nodes)/mynodetype" />

    or

    <xsl:variable name="nodes" select="msxml:node-set($temp_nodes)/*" />

     

     

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jul 08, 2010 @ 14:19
    Matt Brailsford
    1

    Hey Jeroen,

    I've not played to much with 4.5, but something like this should work

    <!-- The nodes which will be displayed. Sorted in the correct order. -->  
    <xsl:variable name="temp_nodes">   
      <xsl:for-each select="$currentPage/NewsItem">     
        <xsl:sort order="descending" select="date" data-type="text"/>     
        <xsl:sort order="descending" select="@createDate" data-type="text"/>     
          <xsl:copy-of select="." />   
      </xsl:for-each> 
    </xsl:variable> 

    <!-- Convert the nodes to a which is easier to work with. --> 
    <xsl:variable name="nodes" select="msxml:node-set($temp_nodes)/NewsItem" /> 

    <!-- The total amount of items --> 
    <xsl:variable name="totalItems" select="count($nodes)" />

    Check out here for differences in schema

    http://our.umbraco.org/wiki/reference/xslt/45-xml-schema

    Matt

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jul 08, 2010 @ 14:20
    Chriztian Steinmeier
    2

    Hi Jeroen,

    Best (if you know which DocumentTypes - call them by name):

    <xsl:variable name="nodes" select="msxml:node-set($temp_nodes)/*[self::DocTypeName1 | self::DocTypeName2]" />

    Good:

    <xsl:variable name="nodes" select="msxml:node-set($temp_nodes)/*[@isDoc]" />

    /Chriztian

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jul 08, 2010 @ 14:24
    Jeroen Breuer
    0

    Wow fast responses!

    @Tommy Poulsen @Matt Brailsford @Chriztian Steinmeier thanks for your reactions. This solved my problem :).

    To replace the /node I now use the /*[@isDoc] since this does the exact same thing.

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft