[xep-support] Re: RenderX to embed SVGs without a need for fo:instream-foreign-object?

From: G. Ken Holman <gkholman@CraneSoftwrights.com>
Date: Thu Nov 29 2012 - 19:03:43 PST

At 2012-11-29 17:51 -0800, Michaud, Jean-Francois wrote:
>Is there a way to set RenderX to embed SVGs in the XEP output from
>an FO input that references the SVGs as an external graphics
>(fo:external-graphic) without having to embed the SVG ourselves in
>an fo:instream-foreign-object prior to RenderX processing the FO?

What would be the purpose of replacing the referenced SVG to be an
in-stream SVG? Do you have a requirement for late binding? If not,
I cannot think there would be a penalty for referencing the SVG
rather than embedding it.

A very straightforward XSLT would be able to do the replacement ...
something along the lines of what is below would be all you
need. I've limited myself to XSLT 1.0 in case you are so limited.

I hope this helps.

. . . . . . . . Ken

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:fo="http://www.w3.org/1999/XSL/Format"
   version="1.0">

<!--only process those external graphics pointing to recognized extension-->
<xsl:template match="fo:external-graphic[contains(@src,'.svg')]">
   <xsl:choose>
     <xsl:when test="substring-before(name(.),':')">
       <xsl:element namespace="{namespace-uri(.)}"
         name="{substring-before(name(.),':')}:instream-foreign-object">
         <xsl:call-template name="graphic-common"/>
       </xsl:element>
     </xsl:when>
     <xsl:otherwise>
       <xsl:element namespace="{namespace-uri(.)}"
                    name="instream-foreign-object">
         <xsl:call-template name="graphic-common"/>
       </xsl:element>
     </xsl:otherwise>
   </xsl:choose>
</xsl:template>

<!--embed the content regardless of how the in-stream element is named-->
<xsl:template name="graphic-common">
   <xsl:copy-of select="@*[name(.)!='src']"/>
   <xsl:variable name="resource">
     <xsl:choose>
       <xsl:when test="contains(@src,'&#x22;')">
         <xsl:value-of
           select="substring-before(substring-after(@src,'&#x22;'),'&#x22;')"/>
       </xsl:when>
       <xsl:when test='contains(@src,"&#x27;")'>
         <xsl:value-of
           select='substring-before(substring-after(@src,"&#x27;"),"&#x27;")'/>
       </xsl:when>
       <xsl:when test='contains(@src,"(")'>
         <xsl:value-of
           select="substring-before(substring-after(@src,'('),')')"/>
       </xsl:when>
     </xsl:choose>
   </xsl:variable>
   <xsl:copy-of select="document($resource,.)/*"/>
</xsl:template>

<xsl:template match="@*|node()"><!--identity for all other nodes-->
   <xsl:copy>
     <xsl:apply-templates select="@*|node()"/>
   </xsl:copy>
</xsl:template>

</xsl:stylesheet>

--
Contact us for world-wide XML consulting and instructor-led training
Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm
Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/f/
G. Ken Holman                   mailto:gkholman@CraneSoftwrights.com
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal
!DSPAM:87,50b8225063731948415766!
_______________________________________________
(*) To unsubscribe, please visit http://lists.renderx.com/mailman/options/xep-support
(*) By using the Service, you expressly agree to these Terms of Service http://w
ww.renderx.com/terms-of-service.html
Received on Thu Nov 29 18:52:08 2012

This archive was generated by hypermail 2.1.8 : Thu Nov 29 2012 - 18:52:13 PST