Normally you just need to double the quote to escape it in Velocity. For example:
#set ($xwql = "from doc.object('Pilotage.Pilotage SST.Règles d''affaires SST.Code.Règles d''affaires SSTClass') as processus where doc.title <> ''")
$services.query.xwql($xwql).execute())
However that won’t work in this case. If you check the stacktrace you get you’ll see:
Caused by: org.xwiki.query.jpql.parser.ParserException: [1,87] expecting: ')'
at org.xwiki.query.jpql.parser.Parser.parse(Parser.java:1385)
at org.xwiki.query.jpql.internal.JPQLParser.parse(JPQLParser.java:46)
at org.xwiki.query.xwql.internal.hql.XWQLtoHQLTranslator.translate(XWQLtoHQLTranslator.java:55)
What this means is that the parser we use to convert from XWQL syntax to Hibernate HQL syntax doesn’t support it. And it seems this parser doesn’t support escaping quotes. See https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-query/xwiki-platform-query-jpql-parser/src/main/sablecc/JPQL.grammar#L16
So right now the only solution I see for you would be to use HQL and not XWQL. See https://extensions.xwiki.org/xwiki/bin/view/Extension/Query%20Module
You could open a jira issue at https://jira.xwiki.org to suggest adding support for quote escapes. It’s an important limitation IMO.
Thanks
PS: You could also rename your doc to not have quotes