To test a method that would transform Text elements in an XML document I wrote two very simple Selectors and applied map/toUpperCase on the resulting Zipper. The result should be that all text elements except those excluded via the first Selector are transformed to upper case. But it only works for furthest-down Text elements. Here's the code:
scala> import com.codecommit.antixml._
import com.codecommit.antixml._
scala> val elemSelector = Selector({case x:Elem if x.name != "note" => x})
elemSelector: com.codecommit.antixml.Selector[com.codecommit.antixml.Elem] = <function1>
scala> val textSelector = Selector({case x:Text => x})
textSelector: com.codecommit.antixml.Selector[com.codecommit.antixml.Text] = <function1>
scala> val xml = XML.fromString("<tei><div><p>this<note>not<foreign lang=\"greek\">that</foreign>not</note></p><p>those<hi>these</hi></p></div></tei>")
xml: com.codecommit.antixml.Elem = <tei><div><p>this<note>not<foreign lang="greek">that</foreign>not</note></p><p>those<hi>these</hi></p></div></tei>
scala> val zipper = xml \\ elemSelector \ textSelector
zipper: com.codecommit.antixml.Zipper[com.codecommit.antixml.Text] = thisthatthosethese
scala> val modified = zipper.map(t => new Text(t.text.toUpperCase))
modified: com.codecommit.antixml.Zipper[com.codecommit.antixml.Text] = THISTHATTHOSETHESE
scala> val result = modified.unselect.unselect
result: com.codecommit.antixml.Zipper[com.codecommit.antixml.Node] = <tei><div><p>this<note>not<foreign lang="greek">THAT</foreign>not</note></p><p>those<hi>THESE</hi></p></div></tei>
So, in the second to last command, the upper case is applied to all targeted Text elements, but after stepping out of the zipper, only two of the four elements are transformed. I've tried it with <hi/>
instead of <hi>these</hi>
and then those
gets capitalized. Any idea what's the problem here?
I am using the arktekk.no fork for Scala 2.10.3.