0

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 :

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

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

0

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

Woaw

2
  • 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 at 20:50
  • Actually it can be both, hence the mistake. I edited to fix the mismatch.
    – JLuc
    May 28 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.