Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: How to extract parent's attributes? How to use patterns to parse attribute's string value? >Thread Next - Re: How to extract parent's attributes? How to use patterns to parse attribute's string value? Re: How to extract parent's attributes? How to use patterns to parse attribute's string value?To: NULL Date: 10/17/2008 7:08:00 PM Siegfried Heintze wrote:
> Now how do I extract that 78.10 and 59.05 out of the translate function in
> the transform attribute?
As suggested, you can try to parse out those value with a regular
expression and xsl:analyze-string.
Here is an example that defines a function to be used:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs mf"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:mf="http://example.com/2008/mf"
version="2.0">
<xsl:output indent="yes"/>
<xsl:template match="/">
<keys>
<xsl:apply-templates select="//svg:text[@class='tch']"/>
</keys>
</xsl:template>
<xsl:template match="*[@class='tch']">
<xsl:element name="key">
<xsl:variable name="parsed-translate"
select="mf:parse-translate(parent::svg:g/@transform)"/>
<xsl:attribute name="x" select="$parsed-translate[1]"/>
<xsl:attribute name="y" select="$parsed-translate[2]"/>
<xsl:value-of select="text()"/>
</xsl:element>
</xsl:template>
<xsl:function name="mf:parse-translate" as="xs:string*">
<xsl:param name="translate" as="xs:string"/>
<xsl:variable name="dp" select="'[+\-]?\d+(\.\d+)?'"/>
<xsl:variable name="pattern" select="concat('translate\s*\(\s*(',
$dp, '),\s*(', $dp, ')\)')"/>
<xsl:message terminate="no" select="concat('pattern is "',
$pattern, '"')"/>
<xsl:analyze-string select="$translate"
regex="{$pattern}">
<xsl:matching-substring>
<xsl:sequence select="(regex-group(1), regex-group(3))"/>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:function>
</xsl:stylesheet>
Here is a link to the documentation again:
http://www.w3.org/TR/xslt20/#analyze-string
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
