I want to remove preceding './' and first folder if it is not named 'screenshots'
So from
<image href="./folderx/screenshots/page1.png">
<image href="./screenshots/page2.png"/>
<image href="./views/screenshots/table/screenshots/page3.png"/>
to
<image href="screenshots/page1.png">
<image href="screenshots/page2.png"/>
<image href="screenshots/table/screenshots/page3.png"/>
The Solution below does this:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE reference
PUBLIC "-//OASIS//DTD DITA Composite//EN" "http://docs.oasis-open.org/dita/v1.1/OS/dtd/reference.dtd">
<reference id="sample">
<title>Sample Title</title>
<refbody>
<section>
<title>Breadcrumb</title>
<p>
<xref href=""/>
<xref href=""/>
<xref href=""/>
</p>
</section>
<section>
<title>Screenshot</title>
<p id="Typ1e">
<image href="./views/screenshots/Type1.png" placement="break"/>
</p>
<p id="Type2">
<image href="./views/screenshots/Type2.png" placement="break"/>
</p>
</section>
</refbody>
</reference>
To:
<reference xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/" id="sample"
ditaarch:DITAArchVersion="1.2"
domains="(topic concept) (topic concept glossentry) (topic concept glossgroup) (topic reference) (topic task) (topic hi-d) (topic ut-d) (topic indexing-d) (topic hazard-d) (topic abbrev-d) (topic pr-d) (topic sw-d) (topic ui-d) (topic task strictTaskbody-c) "
class="- topic/topic reference/reference ">
<title class="- topic/title ">Sample Title</title>
<refbody class="- topic/body reference/refbody ">
<section class="- topic/section ">
<title class="- topic/title ">Breadcrumb</title>
<p class="- topic/p ">
<xref href="" class="- topic/xref "/>
<xref href="" class="- topic/xref "/>
<xref href="" class="- topic/xref "/>
</p>
</section>
<section class="- topic/section ">
<title class="- topic/title ">Screenshot</title>
<p id="Typ1e" class="- topic/p ">
<image href="screenshots/Type1.png" placement="break" class="- topic/image "/>
</p>
<p id="Type2" class="- topic/p ">
<image href="screenshots/Type2.png" placement="break" class="- topic/image "/>
</p>
</section>
</refbody>
</reference>
Using XSLT:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match=
"image/@href[starts-with(.,'./')
and not(starts-with(.,'./screenshots/'))
]">
<xsl:attribute name="href">
<xsl:value-of select="substring-after(substring-after(.,'./'), '/')"/>
</xsl:attribute>
</xsl:template>
<xsl:template match="image/@href[starts-with(.,'./screenshots/')]">
<xsl:attribute name="href">
<xsl:value-of select="substring-after(.,'./')"/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
I'm not sure if this is relevant, but I'm using oXygen 12.0