I have a simple xml file and I want to select 1) the first two occurrence words and 2) the rest in the element using xmlstarlet:
<fig>
<caption>Figure 1: Testing the figure</caption>
</fig>
The results will look like this:
Figure 1:
Testing the figure
I have tried this and it is not working:
xmlstarlet ed -s -v substring(//fig/caption,1,string-length(substring-before(//fig/caption," "))+string-length(substring-before(substring-after(//fig/caption," ")," "))+1) input.xml
Thanks in advance.
Ofuuzo
Will the caption always contain
:? If so, I'd suggest using that for thesubstring-before()and thesubstring-after()...This outputs:
If the caption does not always contain
:, I'd suggest using XSLT. Here's an example...XSLT 1.0 (test.xsl):
xmlstarlet command line:
This produces the same output as above.