0
votes

I get an error if I try to use the xpath 'current()' function in a sitecore query inside a nested expression, something like this:

/sitecore/content/Home/Topics/*[contains(current()/@MainTopics, @@id)]

What I am trying to do is, use this query as a source for my DropLink field to only list 'Topic' items that are already selected in another 'MainTopics' field in the same item.

But this gives me an error, something like ")" expected at position 50

So looks like current() function cannot be used inside the nested expression, or entirely. If not, is there any way to reference the current node and not the context node from within a nested expression?

Any ideas?

2

2 Answers

2
votes

does sitecore query support current() function?

current() is a function defined only in XSLT.

By definition current() produces the node that is matched by the current xsl:template or the node that is selected in an xsl:for-each

As SiteCore doesn't seem to have an XSLT implementation, the answer must be negative.

0
votes

I don't think there's any simple way to do this in Sitecore query.

But to place a data source on a template field that references items chosen in another field (if I've understood right) then one possible solution is to build a custom field. In the code for the custom field you would do some string handling to extend or override Sitecore query, allowing you to add a query type that specified a particular field ID. Essentially you'd have to write your own very basic query language that you could use within your C# code.

You can derive your feild from ValueLookupEx and override the GetItems(Item current) method with your custom query handling. As you can see, it quite handliy comes with the current item provided!

We had a similar requirement which we solved this way.