Subject: 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"
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
|