SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to generate a dynamic CAML query for DataView web part. My requirement is similar to what is mentioned at: .

I'm trying to use following Query:

            <FieldRef Name="ID"/>
                <xsl:for-each select="tokenize($IDs, ',')">
                    <Value Type="Text"><xsl:value-of select="."/></Value>

But I'm not able to use xsl:for-each in CAML query. What could be wrong?

share|improve this question

XSLT code can be used only inside <Xsl> tag of DVWP. <Query> tag can include only CAML elements described in following MSDN article:

There is no way to create a dynamic CAML query using xslt. You can create it either programmatically (from other webpart on same page or by creating a DataViewWebPart descendant), or you can use parameters (from <ParametersBindings>, like this: {nameOfParameter}) - but the latter approach is rather limited and I'm afraid it couldn't be used in your particular situation, because there is no way to split a parameter into pieces using CAML.

share|improve this answer
Can I set value of parameterbinding using JS code / connected webpart? – Vivek Athalye Nov 3 '11 at 10:40
Connected webpart - yes. Also ParameterBindings can be automatically gathered from server controls, form inputs, query string, etc. - depending of Location attribute. But you will be able to use the parameter value only in a limited way, due to CAML query schema limitedness. – Andrey Markeev Nov 3 '11 at 11:02
Thanks for your reply. I'll check how to connect a custom web part with DataView web part. If you have any reference related to this can you please share? – Vivek Athalye Nov 4 '11 at 4:54
I don't, but I anticipate you will need to use SPLimitedWebPartManager to find the DVWP on the page where your custom webpart is placed. – Andrey Markeev Nov 4 '11 at 10:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.