XSLT, Limiting results and Loading Content from Document Type
Hello,
A Little bit of an Umbraco / XSLT noob here, but i have a couple of questions, but first a bit of background.
I have been working on getting Umbraco as our CMS of choice at my place of work, as such i am staging a sample of our website in Umbraco. I have been working with Runway and the Creative Website Starter to try and progress my knowledge, and as such have started to pick up some XSLT basics.
At this point i would like to know, is it possible to limit the number of results that are pulled by XSLT (say using the CWS Navi as an example).
Also is it possible to get data from a document type. for example i have created a Document Template with Blurb, Image (as a link) and display this as output within the XSLT?
I have had a look over thr forums but i am struggling to find a more concise answer.
The second question is not clear to me. Do you mean you have an upload field in a document type defined where you upload a picture for one content node?
Would you specify this question a little bit more,
This tests to see if the current position is is less than your desired amount before doing something, and is an easy way to limit results. Does seem to be a waste of cycles though...
Sure it's possible to limit the number of results received from xslt. All you need is to build the xpath query... all depends on what you define as 'limit the number of results'. Can you give a more specific detailed requirement?
For example, let's start with a simple xslt that returns all child nodes for any page in a list (in xslt, that is referred to as the currentPage, which is a variable declared in almost any xslt example you can find in the dropdown when creating an xslt)
Above snippet will only return the first 5 child nodes. Let's add another restriction. Now, we only want the first 5 child nodes that have a specific value 'MyValue' for a specific property (alias of property = 'propertyAlias'.
XSLT, Limiting results and Loading Content from Document Type
Hello,
A Little bit of an Umbraco / XSLT noob here, but i have a couple of questions, but first a bit of background.
I have been working on getting Umbraco as our CMS of choice at my place of work, as such i am staging a sample of our website in Umbraco. I have been working with Runway and the Creative Website Starter to try and progress my knowledge, and as such have started to pick up some XSLT basics.
At this point i would like to know, is it possible to limit the number of results that are pulled by XSLT (say using the CWS Navi as an example).
Also is it possible to get data from a document type. for example i have created a Document Template with Blurb, Image (as a link) and display this as output within the XSLT?
I have had a look over thr forums but i am struggling to find a more concise answer.
Cheers
Alan
You cannot directly limit the results you get by an xpath statement, but you can test for the position of a node:
with this example you have limited the nodes to 10 (lower than 11).
Thomas
The second question is not clear to me. Do you mean you have an upload field in a document type defined where you upload a picture for one content node?
Would you specify this question a little bit more,
Thomas
Hmm. Perhaps not the cleanest way, but
This tests to see if the current position is is less than your desired amount before doing something, and is an easy way to limit results. Does seem to be a waste of cycles though...
As for getting data from document types, this is fundamental. Try the wiki for more detailed answers, such as http://our.umbraco.org/wiki/how-tos/working-with-document-types
If the xslt is grabbing data on the document type making up the current page, something like this will bring it out
If not on the current page, have a look at http://umbraco.org/documentation/books/xslt-basics/xpath-axes-and-their-shortcuts
Best thing to do would be to look at how the runway and cws get their data on the page and work from there.
Dan
Hi Alan,
Sure it's possible to limit the number of results received from xslt. All you need is to build the xpath query... all depends on what you define as 'limit the number of results'. Can you give a more specific detailed requirement?
For example, let's start with a simple xslt that returns all child nodes for any page in a list (in xslt, that is referred to as the currentPage, which is a variable declared in almost any xslt example you can find in the dropdown when creating an xslt)
<ul><xsl:for-each select="$currentPage/node"><li><xsl:value-of select="@nodeName""/></li></ul>
Above snippet returns a list of child nodes starting from current page. If you'd like to limit the number of items in the list, you could eg.
Above snippet will only return the first 5 child nodes. Let's add another restriction. Now, we only want the first 5 child nodes that have a specific value 'MyValue' for a specific property (alias of property = 'propertyAlias'.
Above snippet will return maximum of 5 child nodes.
Getting the data from the document type (I presume you're after data from the document), is just as easy as using
<xsl:value-of select="@attribute"/>
or
<xsl:value-of select="data [@alias = 'propertyAlias']"/>
First statement can be used to get the value of an attribute, second example gets the value of a property defined on the document type.
For example, to get the id of the current page you're requesting, you'd write:
or
If you need more help, just shout.
Cheers,
/Dirk
is working on a reply...