next
|
Subject: SVG path d --> XSLT Author: Tony Lavinio Date: 22 Mar 2005 05:34 PM
|
The idea is simple - we take one token off the string at a time,
and handle it. If it requires parameters, we take the next token
off the string.
With anything left over, we call ourselves.
For the 'L' line-to instructions, if we see a second set of
coordinates after the first, we insert the extra 'L' and then
call ourselves, so that "L 10,10 20,20" is treated as
"L 10,10 L 20,20".
|
next
|
Subject: SVG path d --> XSLT Author: joe j Date: 22 Mar 2005 09:56 PM
|
Thank you very very much for your help. I really approciate it :-)
One more thing please:
I have another XSLT tranformation from XML to SVG d path. It works fine but
the problem is only the spaces I keep getting..dont know why. I tried many things but
since I am new at this, it might be easy for you.
Here is the code>
<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='Move' mode='in_path'>
<xsl:choose>
<xsl:when test='@position="absolute"'>M</xsl:when>
<xsl:otherwise>m</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="x" /><xsl:text>,</xsl:text><xsl:value-of select="y" />
</xsl:template>
<xsl:template match='Line' 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:template>
<xsl:template match='HLine' 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:template>
<xsl:template match='VLine' mode='in_path'>
<xsl:choose>
<xsl:when test='@position="absolute"'><xsl:text>V</xsl:text></xsl:when>
<xsl:otherwise><xsl:text>v</xsl:text></xsl:otherwise>
</xsl:choose>
<xsl:value-of select='y' />
</xsl:template>
<xsl:template match='Cubic' mode='in_path'>
<xsl:choose>
<xsl:when test='@position="absolute"'><xsl:text>C</xsl:text></xsl:when>
<xsl:otherwise><xsl:text>c</xsl:text></xsl:otherwise>
</xsl:choose>
<xsl:value-of select='xc1' />
<xsl:choose>
<xsl:when test="number(yc1) < number(0)"><xsl:value-of select='yc1' /></xsl:when>
<xsl:otherwise><xsl:text>,</xsl:text><xsl:value-of select='yc1' /></xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="number(xc2) < number(0)"><xsl:value-of select='xc2' /></xsl:when>
<xsl:otherwise><xsl:text>,</xsl:text><xsl:value-of select='xc2' /></xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="yc2 < 0"><xsl:value-of select='yc2' /></xsl:when>
<xsl:otherwise><xsl:text>,</xsl:text><xsl:value-of select='yc2' /></xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="x < 0"><xsl:value-of select='x' /></xsl:when>
<xsl:otherwise><xsl:text>,</xsl:text><xsl:value-of select='x' /></xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="y < 0"><xsl:value-of select='y' /></xsl:when>
<xsl:otherwise><xsl:text>,</xsl:text><xsl:value-of select='y' /></xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match='SCubic' mode='in_path'>
<xsl:choose>
<xsl:when test='@position="absolute"'>
<xsl:text>S</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>s</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select='xc2' /><xsl:text>,</xsl:text>
<xsl:value-of select='yc2' /><xsl:text>,</xsl:text>
<xsl:value-of select='x' /><xsl:text>,</xsl:text>
<xsl:value-of select='y' /><xsl:text>,</xsl:text>
</xsl:template>
<xsl:template match='Quadratic' mode='in_path'>
<xsl:choose>
<xsl:when test='@position="absolute"'>
<xsl:text>Q</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>q</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select='xc' /><xsl:text>,</xsl:text>
<xsl:value-of select='yc' /><xsl:text>,</xsl:text>
<xsl:value-of select='x' /><xsl:text>,</xsl:text>
<xsl:value-of select='y' /><xsl:text>,</xsl:text>
</xsl:template>
<xsl:template match='SQuadratic' mode='in_path'>
<xsl:choose>
<xsl:when test='@position="absolute"'>
<xsl:text>T</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>t</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='Arc' mode='in_path'>
<xsl:choose>
<xsl:when test='@position="absolute"'>
<xsl:text>A</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>a</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select='rx' /><xsl:text>,</xsl:text>
<xsl:value-of select='ry' /><xsl:text>,</xsl:text>
<xsl:value-of select='rot' /><xsl:text>,</xsl:text>
<xsl:value-of select='lf' /><xsl:text>,</xsl:text>
<xsl:value-of select='sf' /><xsl:text>,</xsl:text>
<xsl:value-of select='x' /><xsl:text>,</xsl:text>
<xsl:value-of select='y' /><xsl:text>,</xsl:text>
</xsl:template>
<xsl:template match='close' mode='in_path'>
<xsl:text>Z</xsl:text>
</xsl:template>
and the output is like this when it is XML>>>
<path d="
M 0 , 312
C 40 , 48 , 120 -32 , 160 -6
C 0 , 0 , 5 , 4 , 10 -3
C 10 -103 , 50 -83 , 90 -42
C 0 , 0 , 20 , 12 , 30 , 7
C -2 , 12 -18 , 17 -40 , 17
C -55 -2 -40 , 25 -20 , 35
C 30 , 20 , 35 , 65 -30 , 71
c -50 , 4 -170 , 4 -200 -79
Z
"/>
I tried to remove spaces but it didnt work, can see where and what I should do to achieve this?
thank yo in advance
|
next
|
Subject: SVG path d --> XSLT Author: joe j Date: 31 Mar 2005 06:12 PM
|
Thank you very much for your reply. It was a good tip and I switched to it.
However, the main problem which is transforming the d atribute into xml still there!
I got half-way, thanks to the replies, but what if there was no spaces inbetween or no commas?
The SVG can be formed in to several forms but not alot:
<path d="M20,20,L,30,21,23,22,z"> comma separeted..
<path d="M20,20 L 30,21,23,22 z"> comma & space separeted
<path d="M20 20 L 30 21 23 22z"> space separeted
<path d="M20,20L30,21,23,22z"> comma & space separeted & no space before/after commands
<path d="M20 20L 30,21 L23 22 L 44,55z"> Mixture of the above
I cant think of any other forms but this is the major once I guess and the once I will be using..
thank you
|
|