Subject: RE: Optimizing identity template
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 22 Jan 2009 09:33:30 -0000
|
> 1. load an external SVG file ($basemap).
> 2. copy entire SVG file, adding <circle> as the last element
I would do:
<xsl:template match="svg:svg">
<xsl:copy>
<xsl:copy-of select="child::node()"/>
<svg:circle
cx="100px" cy="100px" r="5px"
fill="#ff0000" stroke="#000000" stroke-width="1px"/>
</xsl:copy>
</xsl:template>
No need to apply-templates all the way down the tree if all you want is a
straight copy.
And a match with the predicate [position()=last()] is potentially very
expensive, though Saxon optimizes it.
Michael Kay
http://www.saxonica.com/
>
> This is for PHP5/libxslt, but there will also be an XSLT
> 2/Saxon version.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:svg="http://www.w3.org/2000/svg">
>
> <xsl:output method="xml" omit-xml-declaration="no"
> indent="yes" encoding="UTF-8"/>
>
> <xsl:template match="/">
> <xsl:apply-templates
> select="document($basemap)/svg:svg"/>
> </xsl:template>
>
> <xsl:template match="/svg:svg/*[position()=last()]">
> <xsl:copy>
> <xsl:apply-templates select="@*|node()"/>
> </xsl:copy>
> <circle xmlns="http://www.w3.org/2000/svg"
> cx="100px" cy="100px" r="5px"
> fill="#ff0000" stroke="#000000" stroke-width="1px"/>
> </xsl:template>
>
> <xsl:template match="node()|@*">
> <xsl:copy>
> <xsl:apply-templates select="@*|node()"/>
> </xsl:copy>
> </xsl:template>
>
> </xsl:stylesheet>
>
> --
> Best regards,
> Jacek Iwaqski
> jiva@xxxxxxx
|