I scan scribus SLA files and wish to find the text having some specific paragraph styles. SLA file format is a quite flat XML format and there are several paragraphs in a row, each being separated with either <trail/> or <para/> tags having a paragraphe style attribute. I can reach the <StoryText> object containing one of these, but i need to reach the tag <ITEXT> coming immediately before it because its CH attributes contains the text i'm looking for.

Here is how i reach the containing StoryText :

xmlstarlet sel -t -c "SCRIBUSUTF8NEW/DOCUMENT/PAGEOBJECT/StoryText [para/@PARENT='SearchedStyle']" myfile.sla

It yields for example :

    <ITEXT CH="Et main&#xAD;te&#xAD;nant"/>
    <ITEXT CH="qu&#x2019;est ce qu&#x2019;on fait&#x202F;?"/>
    <para PARENT="SomeOtherParagraphStyle"/>
    <ITEXT CH="The Calendar"/>
    <trail PARENT="SearchedStyle"/>

I can also reach the <trail PARENT="SearchedStyle"/> but how can i reach the <ITEXT CH="The Calendar"/> node ?

1 Answer 1


Not sure it's the best solution, but here is how i managed to do it :

xmlstarlet sel -t -c "SCRIBUSUTF8NEW/DOCUMENT/PAGEOBJECT/StoryText/trail[@PARENT='SearchedStyle']/preceding-sibling::ITEXT[1]" myfile.sla

And to get its CH attribute value :

xmlstarlet sel -t -v "SCRIBUSUTF8NEW/DOCUMENT/PAGEOBJECT/StoryText/trail[@PARENT='SearchedStyle']/preceding-sibling::ITEXT[1]/@CH" myfile.sla


  • In your XPath query, shouldn't para be trail, as there is no para node with the attribute PARENT with the value SearchedStyle?
    – Kusalananda
    May 28, 2021 at 20:50
  • Actually it can be both, hence the mistake. I edited to fix the mismatch.
    – JLuc
    May 28, 2021 at 21:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .