Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7581805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:16:57+00:00 2026-05-30T18:16:57+00:00

I have a few svg documents with a 1-n Path elements now i wanted

  • 0

I have a few svg documents with a 1-n Path elements now i wanted to change the color of those path elements.

i have haven’t found a way to do this

Svg example document:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" height="45" width="45" version="1.1" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
<g transform="matrix(1.25,0,0,-1.25,0,45)">
<path d="m9 18h18v-3h-18v3"/>
</g>
</svg>

XSLT:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' version='1.0'>
<xsl:template match='path'>
<xsl:copy>
<xsl:attribute name='fill'>red</xsl:attribute>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

What do i need to change to make it add/change the fill attribute to red?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:16:58+00:00Added an answer on May 30, 2026 at 6:16 pm

    I think you misunderstand how XSLT works. It takes an input XML tree and produces a new tree by interpreting your stylesheet. In other words, your stylesheet defines how a completely new tree is produced from scratch, based on the input XML tree.

    It’s important to understand that you are not modifying the original XML tree. It’s like a difference between a purely functional and imperative language. Bottom line: you can’t change the fill attribute to red, you can produce a copy of your original document where the fill attribute is set to red.

    That said, this is more or less how you would do it:

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:svg="http://www.w3.org/2000/svg" version='1.0'>
        <!-- this template is applied by default to all nodes and attributes -->
        <xsl:template match="@*|node()">
            <!-- just copy all my attributes and child nodes, except if there's a better template for some of them -->
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:template>
    
        <!-- this template is applied to an existing fill attribute -->
        <xsl:template match="svg:path/@fill">
            <!-- produce a fill attribute with content "red" -->
            <xsl:attribute name="fill">red</xsl:attribute>
        </xsl:template>
    
        <!-- this template is applied to a path node that doesn't have a fill attribute -->
        <xsl:template match="svg:path[not(@fill)]">
            <!-- copy me and my attributes and my subnodes, applying templates as necessary, and add a fill attribute set to red -->
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
                <xsl:attribute name="fill">red</xsl:attribute>
            </xsl:copy>
        </xsl:template>
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have few variables like this: self.lamp_1 self.lamp_2 self.lamp_3 self.lamp_4 and now i want
I have few textviews and it looks like this now: ramdomName 10.20 - 11.30
I have few question in this regard When you create an internet page, does
I have an EBNF grammar that has a few rules with this pattern: sequence
Have few columns and tables, as follows: NOTE : The names of elements used
I have few years of exp on linux, mainly ubuntu (dual-boot). Now i am
I have read a few questions similar to this, but I can't get my
I have few questions on this as selenium always need windowid to get control
I have few questions about this code: <?php $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv =
I have few layouts (different DataTemplates) with video controls. Creation of this video controls

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.