I have this Lenovo 3000 N100 which I bought in May 2007. From the specification it says that the battery life will last up to 3 hours but it’s not. My battery gets empty after 2 hours or less. Surfing the net informs me that this problem might due to overcharging. I spend lots of time in front of my machine and while I am connected to AC power (and so the battery is charging) I missed to notice that it’s already full. That made me thinking that it might really be the cause of the overcharging. Since then, I removed my battery and connect to AC directly. I barely carried my notebook with me anyways.

The first problem occurred after a couple of months when I tried to reattach the battery. The battery is not charging. The one year warranty is over and so calling the service center won’t help at all. That made me connects to AC directly whenever I used my notebook.

Two months ago the disaster with my Lenovo 3000 N100 turned up. My notebook suddenly shuts off with no reason at all. Sometimes it's running up to 1 hours maximum. But it shuts off even a few minutes after starts up. The fan is running. The machine is still cold (just started up). I booted-up and only opened the CMOS but it still shuts down. I brought my machine to Lenovo Service Center and the engineer told me that the board is corroded. How in the hell my board get corrosion when no liquid has been spilled there since I bought the laptop?!

I can’t do anything. I searched the net and found out that there are so many similar problems with Lenovo 3000 N100 as mine. Money has been wasted. 

 

http://www.google.com/search?hl=en&q=lenovo+n100+suddenly+shuts+off

http://www.consumercomplaints.in/complaints/lenovo-3000-n100-c42859.html

http://www.consumercomplaints.in/bycompany/lenovo-3000-n100-a23239.html

 http://www.experts-exchange.com/Hardware/Laptops_Notebooks/PC_Laptops/Q_23082546.html

 

 

1   Overview

 

The purpose of this article is to describe an approach in getting Sitecore Items using the XSL Extension.

 

2     Target Audience

 

The target audience for this example is a .NET developer and is doing Sitecore development.

 

3     Assumption

 

  1.  Sitecore is fully configured in the development machine.
  2. The /sitecore/content/home/Movies/ node exist and has items. The items should also have ‘Title’ field for our code example to run.  

 

4     Basic Idea

 

The idea is to retrieve Sitecore Items using the XSL Extension and return the Items to the calling XSLT. Unlike the usual way of retrieving a Sitecore Items by means of XPATH, it is more easy and convenient to use the XSL Extension. Using the XSL Extension, a developer can make additional condition or add more logic with the Items s/he wants to retrieve. In this document, an example is presented with the requirement to sort the Items in descending order before returning to the calling XSLT. 

 

5     Development Approach

 

The Environment:

The development environment/ technology used in this example are as follows:

  1. Sitecore 5.3
  2. VS 2008
  3. LINQ
  4. C#
  5. XSL, XSLT

 

The Extension:

 

  • From the Sitecore solution in the Visual Studio, add new class with the name of “MyExtensions.cs”. The code has initial code like below.

 

namespace MyNamespace
{
    public class MyExtensions
    {
        public MyExtensions()
        { }
    }
}

 

  • Add the namespaces System.Xml, System.Xml.XPath in the using section of the class.
  • Add a public function “GetLatestItems” with a return type of XmlNodeIterator. The XPathNodeIterator class provides an iterator over the set of nodes.

  Inside the “GetLatestItems”, add the following code:

public XPathNodeIterator GetLatestItems()
        {
            string node = "/sitecore/content/home/Movies/*";

            IOrderedEnumerable<Item> itemsRetrieved = null;

            itemsRetrieved = GetItems(node);
           
            Packet packet = new Packet();

            if (itemsRetrieved != null)
            {
                ExtractXML(ref packet, itemsRetrieved);
            }
            return packet.XmlDocument.CreateNavigator().Select("//sitecore");
        }

 

Our purpose here is to get the latest items under the /sitecore/content/home/Movies/ node.

 

The itemsRetrieved variable with IOrderedEnumerable of Item type will hold the items that we will retrieve and sorted. The actual retrieval and sorting of items is inside the “GetItems()” method.

 

The packet is responsible for building our XML documents.

 

The ExtractXML() method extracts the XML document or Item and aggregates into the packet variable.

 

And lastly, we create a XPathNavigator object by invoking the CreateNavigator() method of the XmlDocument inside the packet.

 

  • Implement the GetItems() method. Add the following code:

 

private IOrderedEnumerable<Item> GetItems(string node)
        {  
            Database db = Sitecore.Context.Database;
            Item[] nodeItems = db.SelectItems(node);

            if (nodeItems != null)
            {
                var sortedItems = from items in nodeItems
                                  where items.Versions.Count > 0
                                  orderby items.Fields["__created"].Value descending,
                                  items.Fields["Title"].Value ascending
                                  select items;

                return sortedItems;
            }
            return null;
        }

 

The “Sitecore.Context.Database” is the current database being used. We could also specifically use the master database like Factory.GetDatabase(“master”) if we want to.

 

The SelectItems() method of the Database retrieved all the items from the node that we specify. Items will be returned as Item array.

 

From the returned array of Item, we apply the logic to filter what we only want to return to the calling method.

The “where” clause in this example tell us to get only the item in which it has a version in the current language. This is very useful if you have multiple language but some items have no version for a specific language.

 

The “orderby” clause simply sorted the items based on the “__created” field, a field which is Sitecore defined, and by “Title” field.

 

  • Implement the ExtractXML() method. Add the following code:

 

private void ExtractXML(ref Packet packet, IOrderedEnumerable<Item> items)
        {
            if (packet != null && items != null)
            {
                XmlDocument doc;
                foreach (var item in items)
                {
                    doc = new XmlDocument();
                    doc.LoadXml(item.GetOuterXml(false));
                    packet.AddElement(doc.FirstChild);
                }
            }
        }

 

The ExtractXML method simply extracts the Item’s XML representation and added to the packet.

 

  • Compile the project.

 

The web.config:

  1. Inside the <xslExtensions> </xslExtensions> add the following code:

 

<extension mode=”on” type=”MyNamespace.MyExtensions”, MyAssembly” namespace=”www.mydomain.com/myext”

 

The “www.mydomain.com/myext” namespace must be unique. It is used to refer to the MyNamespace.MyExtensions class of the MyAssembly assembly in the XSLT.

 

Implementing the Extension:

  1. Create an XSLT. Add the code below in the namespace declaration above.

 

xmlns:myext="http://www.pluggedinonline.com/myext"

 

It's the prefix for our XSL Extension. It points to the namespace defined in the <xslExtensions> section in the web.config.

 

<xsl:template match="*" mode="main">        
        <ul>
            <xsl:variable name="dataItem" select='myext:GetLatestItems()'/>
            <xsl:for-each select="$dataItem/item">
                <li>
                    <xsl:value-of select="sc:fld('Title',.)"/>
                </li>
            </xsl:for-each>
        </ul>
    </xsl:template>

 

The dataItem will hold the values returned from myext:GetLatestItems(). The next line just loops for each the items returned and display the value of the ‘Title’ field.

 

6     Conclusion

 

While accessing Items directly from the XSL is useful, it is more efficient to use XSL Extension if you have complex logic to perform in retrieving Sitecore Items.

 

7     Reference

 

  1. Creating Sitecore XSL Extension Function

http://sdn5.sitecore.net/Articles/XSL/Using%20XSL%20Extension%20Objects/Creating%20Sitecore%20XSL%20Extension%20Function.aspx

BE.NET 1.5 has been released.

I came across with this bug that our page design doesn't render properly. From the users perspective it might be neglegible 'coz it only dealt with the small line crossing the other section of the page which was not really a big deal - the final look was still good. But not to our architect. 

And so I started checking all the html tags, its styles and everything. All seems fine. I then used Firebug to see what were really rendered in the browser. There I found that some div elements are messed inside other elements which should not be. That suggested that there are some elements that do not have closing tags. Going back to the html markups pointed me to this element:

<div style="clear: both;" />

 It seems fine,right? But it's not. Writing the old right way it should be: 

 <div style="clear: both;" ></div>

 That solved my problem.