Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: How to extract parent's attributes? How to use patterns to parse attribute's string value?

From: Martin Honnen <mahotrash@-----.-->
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 &quot;', 
$pattern, '&quot;')"/>
      <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/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent