A value you create for use within a template which is only defined within the scope of that template.
Parameters and variables are used interchangeably, but how you create them is a bit different. While a parameter is a value which you expect to receive, a variable is something which you define. You refer to both of them with a preceding dollar sign once they are defined.
<xsl:variable> lets you create all sorts of values, from simple static values like:
Most likely, as you’re getting up to speed with Data View Web Parts, you’re going to want to define relatively simple variables. All variables need to have:
A name – This is how you refer to the variable once you’ve created it, like $MyName or $Discipline
A value – You define the value either with a select or “within” the tag (more below).
Here are some relatively straightforward examples:
This defines a simple variable called dvt_1_automode with a value of “0”. I’m going to gloss over what this is used for, but note that rather than using the select attribute, you can also define the value of a variable “inside” the tag. This method is handy if you want to use some script to define a value.
This is another simple text value being assigned to a variable. SharePoint Designer creates this variable to represent the layout type you are using for your DVWP. I’ve never seen it used in any way, and I generally remove it.
This is the single most important variable you will see in a DVWP. This is where we define a variable called Rows which represents the rowset we’ve gotten back from our DataSource. Note that the variable can be called Bob or Strawberry_Jam (note no spaces); Designer just uses the useful mnemonic Rows.
It’s best from an efficiency perspective to add filters to the CAML so that you retrieve as few items as possible to meet your needs. When you set a filter in the Common Data View Tasks, that’s where the filter ends up: in the CAML. However, you may want to further filter the rowset more dynamically, like in the case where you’ve got a parameter on the Query String. When you want to do this more dynamic filtering, you can do it in the definition of the Rows like this:
Anything you place inside the brackets should evaluate to true or false: if the calculation returns true, the item is included in the rowset; if it returns false, the item is not included.
What you can calculate for the value of a variable is pretty much endless. One extremely useful set of functions is available in the ddwrt namespace. Why this isn’t documented more completely and visibly by Microsoft is beyond me, as some of these functions are useful all the time. Thank goodness for Serge van den Oever’s work on this or we would have nothing.
I grouped a filed title and caluculated sum for every indiual group.but i need to calculated for only one perticular group and that total should be shown in a seperate variable.
A(group)
total:251
B(group)
total:210
if i caluculate sum it was showinf for all grouped columns and rows.but i dont want like that i want only for B(group).can you please help me on this.
It’s hard to tell exactly what you’re trying to do and what’s going on, but you should be able to accomplish what you want by customizing the XSL. You’ll need a condition on the totalling logic to only display for group B.
I have a performance question though with these filters. I am using a DVWP on a linked data source. The linked data source contains 2 lists. One list may eventually surpass 5000 items. I am worried about hitting SharePoint’s query size limit. If I apply XSL filtering to my DVWP, will this prevent me from hitting this limit?
For example, this list that may eventually surpass 5000 items grows 300 items per month. If I apply an XSL filter by Month and Year, will this avoid hitting the query size limit?
I can’t be sure you won’t hit the limit without fully understanding your data, but a filter in the XSL doesn’t reduce the number of items returned by the query. To make it less likely that you will hit the limit, do as much filtering as you can in CAML, as that reduces the number of items returned.
Thank you for the reply. I also downloaded “SharePoint 2010 at Work: Tricks, Traps, and Bold Opinions” after you mentioned it in another post. It has some excellent information… thanks!
I need to filter a DVWP where a column contains or doesnt contain values.Ive tried using /dsQueryResponse/Rows/Row[(contains(@ColumnName,$queryvar))] but it would work fine if @ColumnName contains some value..How do I query empty values within the column..Its a datetime field.
In a nutshell,I’d wanna to filter by both conditions..contains and doesnt contain..How can I achieve this thru query string/CAML..since it would take only 1 condition either contains or not contains..so I wud be able to fetch only values that are there in the field.How wud it return those rows where this column has no values..
Thanks a lot..I had to define both the upper and lower limits here i.e [(string-length(@ColumnName)>$QSvariable and string-length(@ColumnName)<=$QSvariable1)or $QSvariable ='*'] as my requirements covered both less than 0 and more than 0 and all..and it worked..
hi,
Need your help on the below example.(DVWP)
I grouped a filed title and caluculated sum for every indiual group.but i need to calculated for only one perticular group and that total should be shown in a seperate variable.
A(group)
total:251
B(group)
total:210
if i caluculate sum it was showinf for all grouped columns and rows.but i dont want like that i want only for B(group).can you please help me on this.
It’s hard to tell exactly what you’re trying to do and what’s going on, but you should be able to accomplish what you want by customizing the XSL. You’ll need a condition on the totalling logic to only display for group B.
M.
Great post!
I have a performance question though with these filters. I am using a DVWP on a linked data source. The linked data source contains 2 lists. One list may eventually surpass 5000 items. I am worried about hitting SharePoint’s query size limit. If I apply XSL filtering to my DVWP, will this prevent me from hitting this limit?
For example, this list that may eventually surpass 5000 items grows 300 items per month. If I apply an XSL filter by Month and Year, will this avoid hitting the query size limit?
I can’t be sure you won’t hit the limit without fully understanding your data, but a filter in the XSL doesn’t reduce the number of items returned by the query. To make it less likely that you will hit the limit, do as much filtering as you can in CAML, as that reduces the number of items returned.
M.
Thank you for the reply. I also downloaded “SharePoint 2010 at Work: Tricks, Traps, and Bold Opinions” after you mentioned it in another post. It has some excellent information… thanks!
Hi Marc
I need to filter a DVWP where a column contains or doesnt contain values.Ive tried using /dsQueryResponse/Rows/Row[(contains(@ColumnName,$queryvar))] but it would work fine if @ColumnName contains some value..How do I query empty values within the column..Its a datetime field.
You can use the string-length function to test if there is a value. However, it’s far more efficient to do the filtering in CAML.
M.
How can I do that..Also in string length I wud need both 0 or more than 0..
It’s not totally clear what you want to do, but you can add a filter to the CAML by using the Filter button on the ribbon.
M.
In a nutshell,I’d wanna to filter by both conditions..contains and doesnt contain..How can I achieve this thru query string/CAML..since it would take only 1 condition either contains or not contains..so I wud be able to fetch only values that are there in the field.How wud it return those rows where this column has no values..
Okay, if you want all items regardless what the value is, you can’t filter in your CAML. The string-length test would look like:
1
/dsQueryResponse/Rows/Row[string-length(@ColumnName) > 0]
M.
Hi Marc
Thanks a lot..I had to define both the upper and lower limits here i.e [(string-length(@ColumnName)>$QSvariable and string-length(@ColumnName)<=$QSvariable1)or $QSvariable ='*'] as my requirements covered both less than 0 and more than 0 and all..and it worked..