[xsl] Optimizing identity template

Subject: [xsl] Optimizing identity template
From: Jacek Iwański <jiva@xxxxxxx>
Date: Thu, 22 Jan 2009 00:52:26 +0100
Hello xsl-list,

 I am wondering whether the following (working) stylesheet could be
 improved. It is supposed to output an SVG map with a
 circle pointing to specific coordinates:

 1. load an external SVG file ($basemap).
 2. copy entire SVG file, adding <circle> as the last element

 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"

        <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 match="/svg:svg/*[position()=last()]">
                        <xsl:apply-templates select="@*|node()"/>
                <circle xmlns="http://www.w3.org/2000/svg";
                cx="100px" cy="100px" r="5px"
                fill="#ff0000" stroke="#000000" stroke-width="1px"/>
        <xsl:template match="node()|@*">
                        <xsl:apply-templates select="@*|node()"/>


Best regards,
Jacek Iwaqski

Current Thread