there is that XML Node
<svg>
<g transform="translate(113.63-359.13)">
<use fill="#f00" xlink:href="#D"/>
<g transform="translate(72.59-8.504)">
<use xlink:href="#E"/>
<path fill="#f00" stroke="#000" stroke-linejoin="round" stroke-linecap="round" stroke-width=".24" d="m6.04 526.26h19.843v4.961h-19.843z"/>
<use xlink:href="#F"/>
</g>
<text x="20.41" y="527.6" fill="#000" font-family="Arial" font-size="8">ProcessOutbound</text>
</g>
</svg>
which can be found by this Xpath
/svg/g[text="ProcessOutbound"]/use
also this work fine
/svg/g[text="ProcessOutbound"]/use/@fill
but for some reasons that xsl is not replaceing #f00 with #00f which is what have tired
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:param name="blue" select="'#00f'"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match='/svg/g[text="ProcessOutbound"]/use'>
<xsl:attribute name='fill'>
<xsl:value-of select="'$blue'"/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
actually the whole svg file is copied but the fill attribute is not replaced. I tried to achive a copy but with the replaced fill value
What is the correct way to replace attribut values with constant values by xsl ?
So the expected result should look like
<g transform="translate(113.63-359.13)">
<use fill="#00f" xlink:href="#D"/>
<g transform="translate(72.59-8.504)">
<use xlink:href="#E"/>
<path fill="#f00" stroke="#000" stroke-linejoin="round" stroke-linecap="round" stroke-width=".24" d="m6.04 526.26h19.843v4.961h-19.843z"/>
<use xlink:href="#F"/>
</g>
<text x="20.41" y="527.6" fill="#000" font-family="Arial" font-size="8">ProcessOutbound</text>
</g>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…