I need a stylesheet to convert my docbook xml files so that they now include a xml:base element to my section tags. How do I go about doing that (since xml:base needs system and node info???)
Input:
<section xmlns="http://docbook.org/ns/docbook" xml:id="voidVisit" version="5">
<title>Void</title>
<section>
<title>Screenshot</title>
<mediaobject>
<imageobject>
<imagedata fileref="screenshots/Dialog.png" />
</imageobject>
</mediaobject>
</section>
</section>
Output:
...
<section xml:id="void" version="5"
xml:base="file:/C:/Projects/my/proj/trunk/spec/module/components/void.xml">
<title>Void</title>
<section>
<title>Screenshot</title>
<mediaobject>
<imageobject>
<imagedata fileref="screenshots/Dialog.png"/>
</imageobject>
</mediaobject>
</section>
...
In XSLT 2.0 (XPath 2.0) the functions
static-base-uri()andbase-uri()can be used for this purpose.Here is a working example:
when this transformation is applied, the wanted result is produced:
So, the complete transformation in your case is:
In XSLT 1.0 the solution is to pass the base-uri as an external parameter (global
xsl:param>) to the transformation.