Copied to clipboard

Flag this post as spam?

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


  • Bo Damgaard Mortensen 712 posts 1189 karma points
    Jan 09, 2011 @ 17:51
    Bo Damgaard Mortensen
    0

    Problems getting values from nodeset

    Hello all,

    I'm having a bit of trouble getting the values from a nodeset. To me it would seem obvious and straight forward, but I simply can't get it to show any output.

    My XSLT (i'll try to explain):

    <xsl:variable name="nodes">
      <!-- GET ALL COMMENTS -->
      <xsl:for-each select="$currentPage/ancestor::root//Kommentar">
         <xsl:sort select="@sortOrder" data-type="number" order="descending" />
        <xsl:if test="position() &lt; 6">
          <xsl:copy-of select="." />
        </xsl:if>
      </xsl:for-each>
      
      <!-- GET ALL ADS -->
      <xsl:for-each select="$currentPage/ancestor::root//Annonce">
         <xsl:sort select="@sortOrder" data-type="number" order="descending" />
        <xsl:if test="position() &lt; 6">
            <xsl:copy-of select="." />
          </xsl:if>
      </xsl:for-each>
    </xsl:variable>
    <xsl:variable name="nodeSet" select="msxml:node-set($nodes)" />  
          
    <xsl:for-each select="$nodeSet">
      <xsl:copy-of select="current()/@id" />
    </xsl:for-each>

    Basically what I want is to get all documents of document type 'Kommentar' and 'Annonce' and display some data from them. Since I have loops inside a variable it seems I have to use the msxml:node-set() method to make a node set out of my variable which is, of course, all good!

    When I try to <xsl:copy-of select="$nodeSet" /> I get the following XML:

    <kommentar id="1205" parentid="1138" level="4" writerid="0" creatorid="0" nodetype="1101" template="1102" sortorder="4" createdate="2011-01-06T18:21:37" updatedate="2011-01-06T18:21:37" nodename="06-01-2011_Bo Mortensen" urlname="06-01-2011_bo-mortensen" writername="Administrator" creatorname="Administrator" path="-1,1053,1064,1138,1205" isdoc="">
        <navn>Bo Mortensen</navn>
        <email>[email protected]</email>
        <website>http://www.mysite.com</website>;
        <kommentar>Dette er en test kommentar!</kommentar>
    </kommentar>

    How exactly do I get these data since current()/@id apperantly doesn't work?

    Thanks in advance! :-)

    / Bo

  • Bo Damgaard Mortensen 712 posts 1189 karma points
    Jan 09, 2011 @ 18:05
    Bo Damgaard Mortensen
    0

    Solved it! :)

    Here's my XSLT for future reference if it's any good at all. As you can see, it's a rather complex task where I'm listing the recent frontend user activity:

    <!-- The fun starts here -->
    <xsl:variable name="nodes">
      <!-- GET ALL COMMENTS -->
      <xsl:for-each select="$currentPage/ancestor-or-self::*/*//Kommentar [@isDoc]">
         <xsl:sort select="@sortOrder" data-type="number" order="descending" />
          <xsl:if test="position() &lt; 6">
          <xsl:copy-of select="." />
        </xsl:if>
      </xsl:for-each>
      
      <!-- GET ALL ADS -->
      <xsl:for-each select="$currentPage/ancestor-or-self::*//Annonce [@isDoc]">
         <xsl:sort select="@sortOrder" data-type="number" order="descending" />
      <xsl:if test="position() &lt; 6">
            <xsl:copy-of select="." />
          </xsl:if>
      </xsl:for-each>
    </xsl:variable>
      
    <xsl:variable name="nodeSet" select="msxml:node-set($nodes)" />  

      <xsl:for-each select="$nodeSet/*">
          <xsl:variable name="parentNode" select="umbraco.library:GetXmlNodeById(current()/@parentID)" />
          <xsl:variable name="parentNodeOfParentNode" select="umbraco.library:GetXmlNodeById($parentNode/@parentID)" />
         
          <!-- ACTIVITY DATE -->
          <span class="activityDate"><xsl:value-of select="umbraco.library:FormatDateTime(current()/@createDate, 'dd-MM-yyyy HH:mm')" /> </span>
        
          <!-- IF CURRENT NODE IS A COMMENT -->
          <xsl:if test="local-name($parentNode) = 'KommentarDato'">       
            &nbsp;<xsl:value-of select="current()//navn" />
            
            <!-- IF CURRENT IS IN GUESTBOOK -->
            <xsl:if test="$parentNodeOfParentNode/@template = '1137'">
              skrev i <a href="{umbraco.library:NiceUrl($parentNodeOfParentNode/@id)}">gæstebogen</a>
            </xsl:if>

            <!-- IF CURRENT IS A NEWS COMMENT -->
            <xsl:if test="local-name($parentNodeOfParentNode) = 'Nyhed'">
              en kommentar til nyheden <a href="{umbraco.library:NiceUrl($parentNodeOfParentNode/@id)}"><xsl:value-of select="$parentNodeOfParentNode/@nodeName" /></a>
            </xsl:if>
            
            <!-- IF CURRENT IS A BUY-SECTION COMMENT -->
            <xsl:if test="local-name(umbraco.library:GetXmlNodeById($parentNodeOfParentNode/@parentID)) = 'Kb'">
              en kommentar til annoncen <a href="{umbraco.library:NiceUrl(current()/@id)}"><xsl:value-of select="$parentNodeOfParentNode/@nodeName" /></a>
              i købssektionen
            </xsl:if>
            
            <!-- IF CURRENT IS A SALE-SECTION COMMENT -->
            <xsl:if test="local-name(umbraco.library:GetXmlNodeById($parentNodeOfParentNode/@parentID)) = 'Salg'">
            en kommentar til annoncen <a href="{umbraco.library:NiceUrl($parentNodeOfParentNode/@id)}"><xsl:value-of select="$parentNodeOfParentNode/@nodeName" /></a>
              i salgssektionen
            </xsl:if>
          </xsl:if>
            
          <!-- IF CURRENT IS A 'BUY' NODE -->
          <xsl:if test="local-name($parentNode) = 'Kb'">
            <strong>&nbsp; Køb: </strong> <xsl:value-of select="current()/navn" /> oprettede annoncen <strong><xsl:value-of select="current()/@nodeName" /></strong>
          </xsl:if>
            
          <!-- IF CURRENT IS A 'SALE' NODE -->
          <xsl:if test="local-name($parentNode) = 'Salg'">
            <strong>&nbsp; Salg: </strong> <xsl:value-of select="current()/navn" /> oprettede annoncen <strong><xsl:value-of select="current()/@nodeName" /></strong>
          </xsl:if>
          <br /><br />
      </xsl:for-each>

    This XLST will be placed on the Master template which means it's being called on every postback! Will this cause a huge overhead? If so, is there a way to sort of.. "cache" the results or something like that?

    Thanks again! :)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies