0

My intention is to somehow clean source files automatically. How to do that in XQuery? (I am not interested in reconstructing the document in memory and storing it as a new one.) It is quite easy to do something similar in case of short and simple elements addressed directly, however, I can’t figure out how to do that dynamically for all the text nodes, if possible.

I would expect something like this could work:

update replace $div[contains(., 'chapter')] with replace(., 'chapter', 'Chapter')

This throws err:XPDY0002 Undefined context sequence for 'self::node()' [source: String]

Apparently, there is a problem in addressing the context with . in the replacing function. But maybe I don’t understand the update thing in general. I am only inspired by the bottom of this article.

Honza Hejzl
  • 874
  • 8
  • 23

1 Answers1

2

Expression to the right of with is independent from expression to the left. So an explicit node/context is needed on both part :

update replace $div[contains(., 'chapter')] with replace($div, 'chapter', 'Chapter')
har07
  • 88,338
  • 12
  • 84
  • 137