M.R.
M.R.

Reputation: 4827

Sitecore xpath query not working

Query 1: /sitecore/content/FR/Cabinet/New Category/Attributes//*[@@TemplateID = '{95793C69-3E37-4CEB-9AF4-FD88276D85AA}']

Query 2: /sitecore/content/FR/Cabinet/New Category/Child Category 1/Attributes//*[@@TemplateID = '{95793C69-3E37-4CEB-9AF4-FD88276D85AA}']

Query 1 works, with no problem - query 2 doesn't work, says expected ::. What's the difference, other than one is one more level deep. It also so happens that /Child Category 1/ actually doesn't have any children in the attributes folder, while /New Category/Attributes does...

UPDATE - so it seems that "Child" is a keyword in Xpath...what is the workaround here?

Upvotes: 2

Views: 2028

Answers (1)

Derek Hunziker
Derek Hunziker

Reputation: 13141

You can escape the category by wrapping it in hashes:

/sitecore/content/FR/Cabinet/New Category/#Child Category 1#/ ...

This also comes in handy when selecting items with fields that contain spaces:

... //*[@#My Spaced Out Field# = '%Hey Yo!%']

If you're building the query dynamically, you may want to consider escaping each token separately, using the .Axes API, or selecting the items using Lucene.

Upvotes: 5

Related Questions