如何有条件地评估SVG的属性?

时间:2014-01-09 20:40:28

标签: xslt svg

我想评估font-size属性是否小于“34”。我怎么能在XSLT中做到这一点?

<?xml version="1.0" encoding="utf-8"?>
     <!-- Generator: Adobe Illustrator 17.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
     <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
     <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="1024px" height="100px" viewBox="0 0 1024 100" enable-background="new 0 0 1024 100" xml:space="preserve">

     <text transform="matrix(1 0 0 1 11.9 60.2537)" fill="#FFFFFF" font-family="'OpenSans'" font-size="35">Text</text>
</svg>

1 个答案:

答案 0 :(得分:1)

这里没有太多的背景,但这应该有所帮助:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>
<xsl:template match="*[@font-size &lt; 34]">
    <xsl:comment>
        <xsl:text>What is this?</xsl:text>
        <xsl:text>A font for ants?</xsl:text>
        <xsl:text>How can we be expected to teach children to learn how to read...</xsl:text>
        <xsl:text>if they can't even see the font?</xsl:text>
        <xsl:text>I don't wanna hear your excuses!</xsl:text>
        <xsl:text>The building has to be at least... three times bigger than this!</xsl:text>
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:comment>
</xsl:template>
</xsl:stylesheet>

应用于此SVG文件时:

<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 17.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="1024px" height="100px" viewBox="0 0 1024 100" enable-background="new 0 0 1024 100" xml:space="preserve">

     <text transform="matrix(1 0 0 1 11.9 60.2537)" fill="#FFFFFF" font-family="'OpenSans'" font-size="35">Bigger Text</text>
     <text transform="matrix(1 0 0 1 11.9 60.2537)" fill="#FFFFFF" font-family="'OpenSans'" font-size="20">Smaller Text</text>
</svg>

给出这个:

<?xml version="1.0"?><!-- Generator: Adobe Illustrator 17.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  --><svg version="1.1" id="Layer_1" x="0px" y="0px" width="1024px" height="100px" viewBox="0 0 1024 100" enable-background="new 0 0 1024 100" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">

     <text transform="matrix(1 0 0 1 11.9 60.2537)" fill="#FFFFFF" font-family="'OpenSans'" font-size="35">Bigger Text</text>
     <!--What is this?A font for ants?How can we be expected to teach children to learn how to read...if they can't even see the font?I don't wanna hear your excuses!The building has to be at least...three times bigger than this!-->
</svg>