Writing some stylesheets for DocBook.
Edit: per the comment below: Yes, this means I am writing customizations based on the DocBook-XSL stylesheets, not rewriting existing DocBook stylesheets.
Is it possible, via an XSL stylesheet, to set a default size/scale for imagedata
elements, particularly in print output?
Essentially I want to set things up such that if I include scalefit
, width
and/or contentdepth
attributes in an imagedata
element, those attributes will be used; however if they aren't included, they will default to scalefit="1" width="100%" contentdepth="100%"
.
Seems straightforward enough, but I'm an XSLT newbie, and googling has gotten me nowhere. Is this possible? How?
Thanks!
Essentially I want to set things up such that if I include
scalefit
,width
and/orcontentdepth
attributes in animagedata
element, those attributes will be used; however if they aren't included, they will default toscalefit="1" width="100%" contentdepth="100%"
.
This transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="imagedata[not(@scalefit|@width|@contentdepth)]">
<imagedata scalefit="1" width="100%" contentdepth="100%">
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</imagedata>
</xsl:template>
</xsl:stylesheet>
when applied on the following XML document:
<t>
<imagedata scalefit="1" width="80%" contentdepth="90%"/>
<imagedata/>
</t>
produces the wanted, correct result:
<t>
<imagedata scalefit="1" width="80%" contentdepth="90%"/>
<imagedata scalefit="1" width="100%" contentdepth="100%"/>
</t>
Explanation: Overriding the identity rule for any imagedata
that has none of the scalefit
, width
and contentdepth
attributes.