Changing the scale of .svg points using XSLT 2.0
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 8
- Joined: Fri Jan 23, 2009 4:46 pm
Changing the scale of .svg points using XSLT 2.0
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
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
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Re: Changing the scale of .svg points using XSLT 2.0
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:
on your sample
it gives
Regards,
George
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>
Code: Select all
<polyline points="208.422,527.212 210.617,527.212 " />
Code: Select all
<polyline points="2084.22,5272.12 2106.17,5272.12"/>
George
George Cristian Bina
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service