Copied to clipboard

Flag this post as spam?

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


  • kannandesikan 48 posts 68 karma points
    Nov 09, 2012 @ 18:50
    kannandesikan
    0

    xslt doubts

    hi,

    iam new to xslt , pls explain to me below code, iam learning on my own,pls guide me

    select="count($currentPage/descendant::*[@isDoc and (self::Education or self::schoolbooks or self::story or self::MoreVideos) and string(umbraco.library:GetXmlNodeById(@id)/date)!=''])

    what is currentPage?

    why we declaring $currentPage/descendant::?

    what is  @isDoc?

    what is umbraco.library?

    why we declare
    umbraco.library:GetXmlNodeById(@id)/date)!=''?



  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Nov 09, 2012 @ 19:15
    Jan Skovgaard
    1

    Hi Kannadeskian

    Where have you found the above example?

    Umbraco uses an XML cache for data, whih is stored in memory. The XML cache contains all the data published from an Umbraco instance.

    The entire XML cache can be found in /App_Data/Umbraco.config. This is all the data your website consists of defined in XSLT.

    The $currentPage parameter, starts in the current context that your XSLT macro is being used on. So if you have a template where you reference a XSLT macro, which is assigned to a document type called "Document", the XSLT file will fetch data from the current page if you have for instance

    Page A and Page B in your content tree...then writing <xsl:value-of select="$currentPage/@nodeName" /> will show "Page A", when you visit "Page A" and "Page B" when visiting "Page B".

    @isDoc is an empty attribute that is added to documents, so it's easy to make sure that we're only parsing document XML elements. This is usefull since properties are also defined as XML and you therefore could have property elements that has the same name as a document element.

    Since we start at the $currentPage context we can use an axis to move up or down the the XML cache - by using the Descendant axis we make sure that we only count the descendants from the $currentPage. In the above example we count on some certain document types called "Education", "Schoolbooks", "Story" and "MoreVideos".

    Umbraco.Library is a namespace refering some built in XSLT extensions that gives us the opportunity to do some more advanced stuff in XSLT. In this case we use an extension to find the XML of a certain document that contains a certain id. In this case I'm guessing it's being used to check if a date property is not empty. You can see a list of umbraco.library extensions here: http://our.umbraco.org/wiki/reference/umbracolibrary

    You can read a bit more about XSLT in Umbraco from the topics found in the right navigation here: http://our.umbraco.org/wiki/reference/xslt

    Be aware though that some of this information might be outdated, since some of it is perhaps written when Umbraco used another XML schema, which relied heavily on attributes instead of elements.

    If you want to learn more XSLT in general, perhaps this book is a good read: http://www.amazon.com/exec/obidos/ASIN/1861005946 - You should be aware that XSLT 2.0 is not supported in Umbraco thought but you should be able to achieve all you need by XSLT 1.0.

    When you feel you know the concepts of XSLT in enough detail I suggest you have a look at the more advanced XSLT stuff in Umbraco at Chriztian Steinmeiers blog (The XSLT wizard of the community) here: http://pimpmyxslt.com/articles/

    I hope this answers makes sense - perhaps you need to read through it sometimes before it makes sense. But please don't hesitate if you need some more detailed explanation of the various topics. I also have a feeling that Chriztian is probably also going to give you some advice in this post. :)

    Happy XSLT'ing.

    /Jan

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Nov 09, 2012 @ 20:40
    Chriztian Steinmeier
    2

    Very good writeup, Jan - I'd just like to chip in with how to read the XPath expression - it goes like this:

    "Count the descendant documents of $currentPage which are either Education, schoolbooks, story or MoreVideos documents, that do not have an empty date property"

    OR a little closer to english:

    Count all the Education, schoolbooks, story and MoreVideos descendants of $currentPage that have a date assigned

    Incidentally, it can be written to execute faster, by ditching the extension call:

    count($currentPage//*[@isDoc][self::Education or self::schoolbooks or self::story or self::MoreVideos][normalize-space(date)])
    /Chriztian
Please Sign in or register to post replies

Write your reply to:

Draft