Copied to clipboard

Flag this post as spam?

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


  • Bryan 29 posts 50 karma points
    Jul 27, 2010 @ 17:31
    Bryan
    0

    Last updated node

    Hey Guys,

    So.. I have a tree:

    • Home
    • Columns

    And the plan is to get the last updated node from Columns and add it to a placeholder in Home.

    This is what I got:

    <?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:output method="xml" omit-xml-declaration="yes"/>
      
      <xsl:param name="currentPage"/>  
      <xsl:param name="ColumnsNodes" select="umbraco.library:GetXmlNodeById(1168)" />
      
      <xsl:template match="/">
        <xsl:variable name="lastUpdatedNode">
          <xsl:for-each select="$ColumnsNodes">
            <xsl:sort select="./@updateDate" order="descending"/>
            <xsl:if test="position() = 1">
              <xsl:copy-of select="." />
            </xsl:if>
          </xsl:for-each>
        </xsl:variable>
        
        <xsl:value-of select="$lastUpdatedNode/@id"/>
        <h2><xsl:value-of select="$lastUpdatedNode/@nodeName"/></h2>
        <div><xsl:value-of select="$lastUpdatedNode/@bodyText"/></div>
        <span><a href="{umbraco.library:NiceUrl($lastUpdatedNode/@id)"/>Lees verder..</a></span>
      </xsl:template>

    </xsl:stylesheet>

    And my error is:

    Error reading XSLT file: \xslt\LatestNews.xslt

    So, im brand new to this, read: just started learning xslt couple of hours ago. Some help would be appreciated :D

    And i've tried to google it, searched the documentation, looked through the old forum(thats why i'm this "far"). Now I'm stuck, whats wrong?

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jul 27, 2010 @ 18:37
    Ismail Mayat
    0

    Bryan,

    On your page with the macro can you tag the following to the url ?umbDebugShowTrace=true this will give trace at bottom of screen and possibly more meaninful error can you post that error here.

    Regards

    Ismail

  • Bryan 29 posts 50 karma points
    Jul 27, 2010 @ 21:06
    Bryan
    0

    How could I forget that?

    Error loading XSLT LatestNews.xslt
    XSLT compile error.
      at System.Xml.Xsl.Xslt.XsltLoader.LoadStylesheet(XmlReader reader, Boolean include)
      at System.Xml.Xsl.Xslt.XsltLoader.Load(Compiler compiler, Object stylesheet, XmlResolver xmlResolver)
      at System.Xml.Xsl.Xslt.Compiler.Compile(Object stylesheet, XmlResolver xmlResolver, QilExpression& qil)
      at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
      at umbraco.macro.CreateXsltTransform(XmlTextReader xslReader, Boolean debugMode)
      at umbraco.macro.getXslt(String XsltFile)
      at umbraco.macro.loadMacroXSLT(macro macro, Hashtable attributes, Hashtable pageElements)
  • Jeff Grine 149 posts 189 karma points
    Jul 27, 2010 @ 23:16
    Jeff Grine
    0

    You're anchor at the bottom is self-closing - "/>Lees verder.." should be ">Lees verder.." That's why it won't compile. If you write these in Visual Studio or in the new version of Umbraco, you'll get compile error checking. Saves me a lot of time.

  • Bryan 29 posts 50 karma points
    Jul 28, 2010 @ 10:23
    Bryan
    0

    @Jeff, Ah.. I see.

    below is the new code, I also forgot the "}" :$

    <span><a href="{umbraco.library:NiceUrl($lastUpdatedNode/@id)}">Lees verder..a>span>

    So now I get the error:

    To use a result tree fragment in a path expression, first convert it to a node-set using the msxsl:node-set() function.
    To use a result tree fragment in a path expression, first convert it to a node-set using the msxsl:node-set() function.
      at System.Xml.Xsl.Runtime.XsltConvert.EnsureNodeSet(IList`1 listItems)

      at System.Xml.Xsl.CompiledQuery.Query.
    match="/">(XmlQueryRuntime
    {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator
    {urn:schemas-microsoft-com:xslt-debug}current, Double
    {urn:schemas-microsoft-com:xslt-debug}position, Double
    {urn:schemas-microsoft-com:xslt-debug}last, IList`1
    {urn:schemas-microsoft-com:xslt-debug}namespaces) in
    ---\xslt\LatestNews.xslt:line
    25
      at
    System.Xml.Xsl.CompiledQuery.Query.(XmlQueryRuntime
    {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator , Double ,
    Double )
      at System.Xml.Xsl.CompiledQuery.Query.Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
      at System.Xml.Xsl.CompiledQuery.Query.Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)

      at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument,
    XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter
    writer)
      at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
      at umbraco.macro.GetXsltTransformResult(XmlDocument macroXML, XslCompiledTransform xslt, Dictionary`2 parameters)
      at umbraco.macro.GetXsltTransformResult(XmlDocument macroXML, XslCompiledTransform xslt)
      at umbraco.macro.loadMacroXSLT(macro macro, Hashtable attributes, Hashtable pageElements)
  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jul 28, 2010 @ 12:21
    Ismail Mayat
    0

    Bryan,

    Just a suggestion if the site is big or going to get bigger the getting of last update date would be quicker if using umbraco examine, lee kelleher has done some xslt extensions for it as well see http://farmcode.org/page/Umbraco-Examine.aspx its on codeplex in the contrib section there is the xslt extensions see http://examine.codeplex.com/

    Regards

    Ismail

  • Bryan 29 posts 50 karma points
    Jul 28, 2010 @ 14:26
    Bryan
    0

    Hey Ismail,

    The site is not going to be that big, i'm guessing that there will be just one newsoverview. But! I got it working, only not the last updated node but just the last node is being used. But I think you can tune the code up to make it the last updated node.

    Solution 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: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:output method="xml" omit-xml-declaration="yes"/>
      
      <xsl:param name="currentPage"/>   
      <xsl:param name="columnNode" select="$currentPage/../Newslist[@isDoc and @nodeName='Columns']/Newspage[position()=last()]" />
         
      <xsl:template match="/">    
        <h2><xsl:value-of select="$columnNode/@nodeName"/></h2>
        <div><xsl:value-of select="$columnNode/bodyText" disable-output-escaping="yes"/></div>
        <span><a href="{umbraco.library:NiceUrl($columnNode/@id)}">Lees verder..</a></span>
      </xsl:template>

    </xsl:stylesheet>

    Using Umbraco 4.5.1 here people.

    Can someone mark this thread as solved?

  • Jeff Grine 149 posts 189 karma points
    Jul 28, 2010 @ 14:42
    Jeff Grine
    0

    Bryan - this won't quite get you the same thing. That should get you the last node in terms of the sort order of the tree, but that can be changed by your users. When you assign a variable a value this way (not using the select attribute), you do need to convert it to a node set using msxml:node-set(). (That's msxml, not msxsl.) Just create another variable and assign it msxml:node-set($lastUpdatedNode).

    Ismail - that's an interesting idea using Examine to select a node instead of xslt. Is it really faster for big sites? I would think the code above would still perform pretty well. Is it because the Examine indexes would already have update dates sorted?

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jul 28, 2010 @ 15:03
    Ismail Mayat
    0

    Jeff, Examine uses lucene search engine which is lightening quick I have done something similar in the past, you use an xslt extension method that calls examine that calls , you could also do it with c# in the template as well

    Regards

    Ismail

  • Bryan 29 posts 50 karma points
    Jul 29, 2010 @ 14:22
    Bryan
    0

    Ok, so i've decided this solution was not the best. I want to sort it on his createData.

    I have:

    version="1.0" encoding="UTF-8"?>
    DOCTYPE xsl:stylesheet [ ENTITY nbsp " "> ]>
    <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:output method="xml" omit-xml-declaration="yes"/>  
      <xsl:param name="currentPage"/>   
      <xsl:param name="columnNodes" select="$currentPage/../Newslist[@isDoc and @id=1168]" />
         
      <xsl:template match="/">  
        <xsl:variable name="columnNode">
          <xsl:for-each select="$columnNodes/Newspage">
            <xsl:sort select="@createDate" order="descending" />
            <xsl:if test="position() = 1">
              <xsl:copy-of select="current()" />
            xsl:if>
          xsl:for-each>
        xsl:variable>
       
        <xsl:variable name="lastCreatedNode" select="msxml:node-set($columnNode)" />
        <xsl:value-of select="$lastCreatedNode/@id" disable-output-escaping="yes"/>
        
        
      xsl:template>

    xsl:stylesheet>

    Wich gives no error but also no output. And the output when I print the value of $lastCreatedNode is:

     <div title="Macro Tag: 'LatestNews'" style="border: 1px solid #009;">02010-07-28T00:00:00Admin0InfoColumn2
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer
    in urna sollicitudin magna aliquet lacinia eget ac nisi. Sed vel mi
    et nisi imperdiet pulvinar ut pellentesque sem. Phasellus ipsum
    nulla, pharetra quis iaculis eget, lacinia quis lectus.
    Pellentesque iaculis ultrices diam, tristique adipiscing libero
    mattis nec. Mauris facilisis orci vitae sem vulputate placerat et
    in justo. Nam tortor nulla, malesuada eu eleifend eu, gravida sed
    metus.p>

    <p>Dit is nog een column test paginap>

    This is all the data(property's value i've made) as I dont see the id and nodeName.

  • Jeff Grine 149 posts 189 karma points
    Jul 29, 2010 @ 14:49
    Jeff Grine
    0

    Try this:

    <xsl:variable name="lastCreatedNode" select="msxml:node-set($columnNode)/Newspage" />

  • Bryan 29 posts 50 karma points
    Jul 29, 2010 @ 14:54
    Bryan
    0

    Thats it Jeff! Thanks!

  • cris2per 3 posts 23 karma points
    Nov 25, 2010 @ 15:17
    cris2per
    0

    A great start to my morning.

     

    tampa seo

Please Sign in or register to post replies

Write your reply to:

Draft