[Haskell-beginners] HXT followingSiblingAxis && transform on this and the thing before

Rene@gmail rtbtobi at gmail.com
Sun Sep 22 11:49:03 CEST 2013


Hello,

I'd like to move around and transform some nodes in the following structure:

<vol>
<col pg="1" s="a"/>

<art><p>Text of article 1</p></art>
<art><p>Text of article 2</p></art>

<col pg="1" s="b"/>

<art><p>Text of article 3</p></art>
<art><p>Text of article 4</p></art>

</vol>

Namely, I want to move COL in between each of the next two (or more) 
ART-Tags (<art><col../>...</art>. (So maybe "move" is the wrong word. I 
want to cut COL and paste it in multiple ART-Tags.) Plus when moving one 
COL in, I'd like to give the corresponding ART a new attribute with a 
counter (n="[1..]"), so that the articles in one column are numbered.

So, to begin with, how do I get a COL-milestone together with the 
following ARTs (but of course without the next COL) ? (if that's the 
right way to do what I want to do..)
I tried this:

{-# LANGUAGE TupleSections, Arrows, NoMonomorphismRestriction #-}

import Text.XML.HXT.Core
import Control.Arrow.ArrowNavigatableTree

file = "../auswahl_few16.xml"

main = do

     runX (configSysVars [withCanonicalize no, withValidate no, withTrace 0, withParseHTML no] >>>

           readDocument [withErrors no, withWarnings no] file

           //> hasName "col" >>> addNav >>> followingSiblingAxis >>> remNav >>>

           putXmlTree "-")

Which gives me an empty list. Then this:

  //> (hasName "col" <+> (addNav >>> followingSiblingAxis >>> remNav)) >>> putXmlTree "-"

And there are my old results for COL, but again nothing for the siblings.

In fact, it seems I have no clue, how to use followingSiblingAxis, and 
then again if it worked out, I'm not sure if my selection really is the 
one I need (maybe I get the siblings then only -- without the COL?). 
UPDATE: Thanks to this SO-Question 
(http://stackoverflow.com/questions/4767430/xpath-axis-get-all-following-nodes-until), 
using hxt-xpath I was able to evaluate

(//col)[1]/following-sibling::art [1 = count (preceding-sibling::col[1] | (//col)[1])]

to the first pair of ART-siblings. So that's very nice, but again not 
really what I want. I want to process every COL with its siblings and I 
hope HXT-Arrows offers a somewhat elegant solution to this.

Thanks in advance,
René T.



More information about the Beginners mailing list