I’m exporting an XML file from InDesign. The text in this file contains superscripts referring to a specific grammatical concept; however, these superscripts are exported as text in the XML file. I need to write an XSLT so that when it’s applied to the InDesign file it will simply add a little tag to the superscript.
This is how it’s exported:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Root>
<Content>
<PhraseNative aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="260.5">
<Phrase> 1. Mark is1a playing2 videogames.</Phrase>
</PhraseNative>
</Content>
</Root>
This should be the final code.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Root>
<Content>
<PhraseNative aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="260.5">
<Phrase> 1. Mark is<tag>1a</tag> playing<tag>2</tag> videogames.</Phrase>
</PhraseNative>
</Content>
</Root>
These tags would always appear whenever a number and a letter are the two or three last digits of a string. Sometimes it will be only a number. The output doesn’t change at all. This is just so the tags are not lost when exported back into a web page.
You tagged the question with XSLT 2.0, so here’s a 2.0 option.
Note: I had to add a dummy xmlns for the
aidprefix.Also, you’ll most likely need to refine the regex, but this should get you started.
XML Input
XSLT 2.0
XML Output
Tested using Saxon-HE 9.3.