This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: XSLT and SVG
- To: xsl-list at mulberrytech dot com
- Subject: Re: XSLT and SVG
- From: AndrewWatt2000 at aol dot com
- Date: Sun, 17 Sep 2000 03:33:28 EDT
- Reply-To: xsl-list at mulberrytech dot com
In a message dated 17/09/00 05:10:13 GMT Daylight Time, Chris@Bayes.co.uk
writes:
> 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
Chris,
Thanks and apologies. First, thanks for your detailed reply. Second, my
apologies. I did succeed in getting SVG to SVG transformations working
yesterday, at least for simple transformations and didn't report that back to
the list or to you.
I believe my original problem related to the (now) known problems with using
<xsl:for-each) which was what I happened to use in the original code. I was
getting zero output in the output document (which, I believe, is distinct
from the failure to display problem which I return to later), except for the
XML declaration mentioned below. When I started again from a bare SVG
template and progressively added elements and attributes then they copied
across to the output document as I would expect them to.
I happen to be using the July 2000 preview of MSXML. It adds "<?xml
version="1.0" encoding="utf-8"?>" routinely to all output for SVG to SVG.
Regarding the problems with failure to display output SVG I think this may
partly relate to your using a .xml file extension for your source document. I
am assuming that your problem occurs when you do a "Preview in Browser" or
similar in some integrated environment. If, as I guess, you are using IE5 or
5.5 then it fails to "realise" that the output is SVG, given that the input
was a .xml file and the Adobe SVG Viewer is not called on. If you rename your
source document with a .svg extension then IE5.5, at least, will recognise
that it needs the Adobe SVG viewer and will, I expect, display the output SVG
appropriately.
Also, it may help you to swap over the values of the doctype-system and
doctype-public attributes of <xsl:output>. At least with July 2000 that
produced the correct DOCTYPE declaration in the output file. With July 2000
MSXML the presence of the encoding attribute didn't seem to cause any problem.
Yes, there does appear to be an issue with whitespace, but I haven't had
enough time yet to decide exactly what is happening there.
For testing more "real world" transformations of style attributes I had
planned to use <xsl:attribute-set> but haven't had the opportunity to try
that out yet.
Thanks for your thoughtful reply.
Andrew Watt
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list