Subject: RE: XSLT and SVG From: "Chris Bayes" <Chris@xxxxxxxxxxx> Date: Sun, 17 Sep 2000 02:27:09 +0100 |
>Hi, > >I was wondering if anyone on the list had been able to get XSLT to >successfully produce altered SVG i.e. transform an SVG source >document to an >SVG output document. For example, altering the value of some attributes. > >I am not asking about transforming XML source documents to SVG >output using >XSLT. That is fairly straightforward. > >However, I can't seem to get SVG to SVG transformations working at all. I >would appreciate any suggestions, or even a simple working code sample. > >By the way, I am using Instant Saxon 5.4.1. Andrew, Your question prompted me to play around with this a little. I decided that one of the difficult things to do was to change a css property within a style attribute. Normally I would do my styling solely within my xslt stylesheet and ignore any styling in the xml document but with SVG you have your styling in the source document so it is not that easy. i.e. <polyline id="polyline-03" style="fill:blue; stroke:#00FF00; stroke-width:4" points="310,80,335,180,360,80,385,180,410,80,435,180" /> <text style="font-family:Helvetica;font-size:12;" x="340" y="202">filled & stroked</text> So I decided to write an xslt that would change one css property of the xml in the stylesheet. If you want to change more than one or two then it is probably easier to just replace the style attribute but they can get quite large so you wouldn't want to do that for just say the fill or stroke colour. I came up with this <xsl:template match="polyline"> <xsl:copy> <xsl:apply-templates select="@*[name() != 'style']"/> <xsl:attribute name="style"> <xsl:call-template name="changecssproperty"> <xsl:with-param name="style" select="@style" /> <xsl:with-param name="cssproperty">stroke:red</xsl:with-param> </xsl:call-template> </xsl:attribute> <xsl:apply-templates select="node()"/> </xsl:copy> </xsl:template> The stylesheet will be available some time tomorrow at www.bayes.co.uk/xml/index.xml?/xml/utils/changecssproperty.xml and an explanation at www.bayes.co.uk/xml/index.xml?/xml/tutorial/changecssproperty.xml This raised a lot of problems. The SVG viewer often would not display anything even though it looked like i had produced a valid SVG document. With MSXML2 it insisted on outputting <?xml version="1.0" encoding="UTF-16" standalone="yes"?> even though i had <xsl:output method="xml" encoding="UTF-8" indent="yes" doctype-system="-//W3C//DTD SVG 20000303 Stylable//EN" doctype-public="http://www.w3.org/TR/2000/03/WD-SVG-20000303/DTD/svg-2000030 3-stylable.dtd" standalone="yes" /> in my stylesheet which caused an error encoding specified in XML declaration is incorrect: line1, column 30 If you remove the encoding then it works fine. As I was working on this I was checking against saxon as usual. Everything looked fine but I couldn't get it to do the actual replace. When I checked the output instead of getting a copy of the style attribute I was getting spaces. i.e. style="font-family:Helvetica;font-size:12;" became style="font-family:Helvetica; font-size:12;" and was not getting the property replaced. I changed my test to normalize-space but this still wouldn't change anything. I still got the same output as input. So what looked like a simple answer to a simple problem *isn't*. Maybe Ms and Mike can shed some light on this Ciao Chris XML/XSL Portal http://www.bayes.co.uk/xml XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: XSLT and SVG, Steve Muench | Thread | Re: XSLT and SVG, Chris Lilley |
RE: Rendering: filling tag attribut, Robert C. Lyons | Date | Re: Rendering: filling tag attribut, Dmitry Kachaev |
Month |