[Home] [By Thread] [By Date] [Recent Entries]
At 10:17 20/04/2001 +0100, Henry S. Thompson wrote: >Robin Berjon <robin@k...> writes: >> Size otoh is not really a good argument. Gz-compressed SVG is really small >> (smaller than the other vector graphic formats that I've benchmarked it >> against), and it wouldn't be much larger if paths used markup instead. >> However, SVG paths wouldn't be much more humanly readable as markup than >> they are as strings so that point is pretty moot in the context of SVG > >Disagree -- if they used markup I could use XSL(T) on them, which I >would really like to do! I was just addressing the points that had been listed, ie readability and size. I wholeheartedly agree that being able to transform some path vocabulary into SVG using XSLT is very interesting. As things stand now, I don't think that it is impossible however. Given the following vocabulary: <path> <d> <moveto position='absolute' x='100' y='150' /> <lineto position='relative' x='80' y='10' /> <horizontal-lineto position='absolute' x='200' /> <closepath /> </d> </path> to be transformed into <path d='M 100 150 l 80 90 H 200 z' /> (if my SVG isn't too rotten), the following XSLT seems to do the job (in Saxon): <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'> <xsl:output omit-xml-declaration='yes' /> <xsl:strip-space elements='*' /> <xsl:template match='path'> <xsl:element name='path'> <xsl:attribute name='d'> <xsl:apply-templates mode='in_path' /> </xsl:attribute> </xsl:element> </xsl:template> <xsl:template match='moveto' mode='in_path'> <xsl:choose> <xsl:when test='@position="absolute"'><xsl:text>M </xsl:text></xsl:when> <xsl:otherwise><xsl:text>m </xsl:text></xsl:otherwise> </xsl:choose> <xsl:value-of select='@x' /><xsl:text> </xsl:text> <xsl:value-of select='@y' /><xsl:text> </xsl:text> </xsl:template> <xsl:template match='lineto' mode='in_path'> <xsl:choose> <xsl:when test='@position="absolute"'><xsl:text>L </xsl:text></xsl:when> <xsl:otherwise><xsl:text>l </xsl:text></xsl:otherwise> </xsl:choose> <xsl:value-of select='@x' /><xsl:text> </xsl:text> <xsl:value-of select='@y' /><xsl:text> </xsl:text> </xsl:template> <xsl:template match='horizontal-lineto' mode='in_path'> <xsl:choose> <xsl:when test='@position="absolute"'><xsl:text>H </xsl:text></xsl:when> <xsl:otherwise><xsl:text>h </xsl:text></xsl:otherwise> </xsl:choose> <xsl:value-of select='@x' /><xsl:text> </xsl:text> </xsl:template> <xsl:template match='closepath' mode='in_path'> <xsl:text>z</xsl:text> </xsl:template> </xsl:stylesheet> So it is indeed possible. Another alternative would be to send the data as-is within an SVG document and to put everything within the d element (inclusive) inside a different namespace. You'd then simply getElementsByTagNameNS your namespace and process their values using the DOM to append to the path element's d attribute. I've used this technique previously to extend SVG and it works marvels with Adobe's SVG viewer. _______________________________________________________________________ Robin Berjon <robin@k...> -- CTO k n o w s c a p e : // venture knowledge agency www.knowscape.com ----------------------------------------------------------------------- All fangs and no brain.
|

Cart



