Page 1 of 1
Changing the scale of .svg points using XSLT 2.0
Posted: Fri Jan 23, 2009 5:16 pm
by willisd1
The stylesheet I am currently working on transforms the .svg output of one program into the correct .svg input to another program. Everything works well except the scale. How do I change the scale of all <g> entities using xslt 2.0?
Stylesheet example:
<xsl:attribute name="points">
<xsl:value-of select="@points * 10"/>
</xsl:attribute>
This does not work because the points attribute is a string.
Source document example:
<polyline points="208.422,527.212 210.617,527.212 " />
Any help is appreciated.
Sean
Re: Changing the scale of .svg points using XSLT 2.0
Posted: Fri Jan 23, 2009 5:55 pm
by george
Well, you need to split the @points string value to get the numbers, multiply them and then reconstruct the @points with the new values, see below:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@points">
<xsl:variable name="newPoints"
select="for $k in (for $i in tokenize(., ' ')
return tokenize($i, ',')) return 10*number($k)"/>
<xsl:attribute name="points">
<xsl:value-of select="$newPoints[not(position()>2)]" separator=","/>
<xsl:text> </xsl:text>
<xsl:value-of select="$newPoints[position()>2]" separator=","/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
on your sample
Code: Select all
<polyline points="208.422,527.212 210.617,527.212 " />
it gives
Code: Select all
<polyline points="2084.22,5272.12 2106.17,5272.12"/>
Regards,
George
Re: Changing the scale of .svg points using XSLT 2.0
Posted: Fri Jan 23, 2009 6:49 pm
by willisd1
That worked beautifully. Thank you very much.
Sean