Zipping zippers in Anti-XML

mavaadery

New Member
In this question, the asker wants to transform documents like this:\[code\]<text> The capitals of Bolivia are <blank/> and <blank/>.</text>\[/code\]Into this:\[code\]<text> The capitals of Bolivia are <input name="blank.1"> and <input name="blank.2">.</text>\[/code\]As I noted in my answer there, Anti-XML's zippers provide a clean solution to this problem. The following, for example, would work for renaming the blank elements:\[code\]import com.codecommit.antixml._val q = <text>The capitals of Bolivia are <blank/> and <blank/>.</text>.convert(q \\ "blank").map(_.copy(name = "input")).unselect\[/code\]Unfortunately the following doesn't work:\[code\](q \\ "blank").zipWithIndex.map { case (el, i) => el.copy( name = "input", attrs = Attributes("name" -> "blank.%d".format(i + 1)))}.unselect\[/code\]Because of course once we've \[code\]zipWithIndex\[/code\]-ed the zipper we no longer have a zipper, just an \[code\]IndexedSeq\[/code\]
 
Top