Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

xPath Exception about the paths with digits

Avatar

Level 7

Hi All,

 

We found that QueryManager throws exception about path with digits. For instance the following query will trigger the exception:

/jcr:root/content/mysite/events/2024/special-events//element(*,cq:PageContent)[@sling:resourceType='mysite/pages/event-detail' ] order by @datestamps ascending

 

It will automatically append an "*" to 2024, making it as /jcr:root/content/mysite/events/2024(*)/special-events//element(*,cq:PageContent)[@sling:resourceType='mysite/pages/event-detail' ] order by @datestamps ascending.

So that it will throw an exception

 

Is there any solution getting rid of this?

 

Thanks!

 

-kt

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @kevingtan 
It seems, first character is required to be non-digit, you can switcg to SQL/SQL2 or use Query Builder query

QueryBuilder Example example :

 

path=/content/mysite/events/2024/special-events
type=cq:PageContent
property=sling:resourceType
property.value=mysite/pages/event-detail
orderby=@datestamps
orderby.sort=desc

 

 

 

arunpatidar_0-1717687208693.png

 



Arun Patidar

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

Hi @kevingtan 
It seems, first character is required to be non-digit, you can switcg to SQL/SQL2 or use Query Builder query

QueryBuilder Example example :

 

path=/content/mysite/events/2024/special-events
type=cq:PageContent
property=sling:resourceType
property.value=mysite/pages/event-detail
orderby=@datestamps
orderby.sort=desc

 

 

 

arunpatidar_0-1717687208693.png

 



Arun Patidar

Avatar

Level 9

Hi @kevingtan ,

The issue you are experiencing with the XPath query and paths containing digits is due to the way XPath handles paths that start with a digit. According to the XPath specification, a path step that starts with a digit is not valid syntax.

To work around this issue, you can use the `fn:name()` function in your XPath query to match the nodes based on their name instead of the path. Here's an example of how you can modify your query:

```xpath
/jcr:root/content/mysite/events//*[fn:name() = '2024']/special-events//element(*,cq:PageContent)[@sling:resourceType='mysite/pages/event-detail'] order by @datestamps ascending
```

By using the `fn:name()` function, you can match the nodes with the name "2024" without encountering the syntax issue.

Alternatively, if you have control over the node structure, you can consider prefixing the node name with a letter or a non-digit character to avoid the XPath syntax limitation.

It's important to note that the solution provided assumes you are using XPath queries in AEM. If you are using JCR-SQL2 queries, you may need to adjust the syntax accordingly.

If the issue persists or if you have further questions, it is recommended to reach out to Adobe Support or your AEM implementation partner for further assistance.