m:mediaobject-output-adjust
m:mediaobject-output-adjust — Adjust the URI references to media objects.
Description
Once the stylesheets have used the
$mediaobject-input-base-uri
,
$mediaobject-output-base-uri
,
and $mediaobject-output-paths
to compute
the URI of a media reference, the reference is processed in
m:mediaobject-output-adjust
mode. This is the stylesheet’s
opportunity to make any final adjustments.
The context item for the template will be the
attribute that contains the author’s original value. The
adjusted value is passed in as the $adjusted-uri
parameter.
The value returned by the template is used in the HTML.
Here is an example that groups images, audio, and video files in their own directories:
1 |<xsl:template match="@*" mode="m:mediaobject-output-adjust">
| <xsl:param name="adjusted-uri" as="xs:string"/>
|
| <xsl:choose>
5 | <xsl:when test="exists(f:uri-scheme(.))">
| <!-- Don't mess with absolute URIs... -->
| <xsl:sequence select="$adjusted-uri"/>
| </xsl:when>
| <xsl:otherwise>
10 | <xsl:variable name="type" as="xs:string">
| <xsl:choose>
| <xsl:when test="../self::h:img">image</xsl:when>
| <xsl:when test="ancestor::h:video">video</xsl:when>
| <xsl:when test="ancestor::h:audio">audio</xsl:when>
15 | <xsl:otherwise>
| <xsl:sequence select="'media-cleanup-err'"/>
| </xsl:otherwise>
| </xsl:choose>
| </xsl:variable>
20 |
| <xsl:variable name="parts" select="tokenize($adjusted-uri, '/')"/>
| <xsl:sequence select="string-join($parts[position() lt last()], '/')
| || (if (count($parts) gt 1) then '/' else '')
| || $type || '/'
25 | || $parts[position() eq last()]"/>
| </xsl:otherwise>
| </xsl:choose>
|</xsl:template>
In other words, if the adjusted URI for an image is
path/to/somewhere.png
, this template will
return path/to/image/somewhere.png
and make
similar adjustments to the audio and video paths.