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 8952025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:46:52+00:00 2026-06-15T13:46:52+00:00

Using http://xslt.online-toolz.com/tools/xslt-transformation.php .xml <?xml version=1.0?> <my:project xmlns:my=http://myns> <my:properties> <my:property> <my:name>customerId</my:name> <my:value>1</my:value> </my:property> <my:property> <my:name>userId</my:name>

  • 0

Using http://xslt.online-toolz.com/tools/xslt-transformation.php

.xml

<?xml version="1.0"?>
<my:project xmlns:my="http://myns">
<my:properties>
 <my:property>
  <my:name>customerId</my:name>
  <my:value>1</my:value>
 </my:property>
 <my:property>
  <my:name>userId</my:name>
  <my:value>20</my:value>
 </my:property>
</my:properties>
</my:project>

I now want to look for the name customerId and want to replace the value.

It almost works, but it replaces ALL values in the document. What am I doing wrong to just replace the value where the name mached?

.xsl

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:my="http://myns" xmlns:saxon="http://saxon.sf.net"> 

 <xsl:param name="name" select="'customerId'"/>
 <xsl:param name="value" select="'0'"/>

  <xsl:template match="node() | @*">
    <xsl:copy>
      <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
 </xsl:template>

 <xsl:template match="/*/my:properties/my:property/my:value/text()" > 
   <xsl:choose>
     <xsl:when test="/*/my:properties/my:property/my:name = $name">
        <xsl:value-of select="$value"/>
     </xsl:when>
     <xsl:otherwise><xsl:copy-of select="saxon:parse(.)" /></xsl:otherwise>
   </xsl:choose>
 </xsl:template>
</xsl:stylesheet>
  • 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-06-15T13:46:54+00:00Added an answer on June 15, 2026 at 1:46 pm

    The test for /*/my:properties/my:property/my:name = $name always succeed because it uses an absolute path, and so the result is independent of the surrounding template context. A test with a relative xpath should work.

    XSL:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:my="http://myns" xmlns:saxon="http://saxon.sf.net"> 
    
        <xsl:param name="name" select="'customerId'"/>
        <xsl:param name="value" select="'0'"/>
    
        <xsl:template match="node() | @*">
            <xsl:copy>
                <xsl:apply-templates select="node() | @*"/>
            </xsl:copy>
        </xsl:template>
    
        <xsl:template match="/*/my:properties/my:property/my:value/text()" > 
            <xsl:choose>
                <xsl:when test="../../my:name = $name">
                    <xsl:value-of select="$value"/>
                </xsl:when>
                <xsl:otherwise>otherwise</xsl:otherwise>
            </xsl:choose>
        </xsl:template>
    </xsl:stylesheet>
    

    XML:

    <my:project xmlns:my="http://myns">
        <my:properties>
            <my:property>
                <my:name>customerId</my:name>
                <my:value>1</my:value>
            </my:property>
            <my:property>
                <my:name>userId</my:name>
                <my:value>20</my:value>
            </my:property>
        </my:properties>
    </my:project>
    

    Result of saxonb-xslt -s:test.xml -xsl:test.xsl

    <my:project xmlns:my="http://myns">
        <my:properties>
            <my:property>
                <my:name>customerId</my:name>
                <my:value>0</my:value>
            </my:property>
            <my:property>
                <my:name>userId</my:name>
                <my:value>otherwise</my:value>
            </my:property>
        </my:properties>
    </my:project>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using http://xpath.online-toolz.com/tools/xpath-editor.php as an online XPath evaluator. I tried a few others
I'm using XSLT 2.0. Here is my first file. <?xml version=1.0 encoding=UTF-8?> <xsl:stylesheet xmlns:xsl=http://www.w3.org/1999/XSL/Transform
I'm starting using XSLT and write this scipt: <?xml version=1.0 encoding=ISO-8859-1?> <xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform>
I am following the tutorial here: http://www.aspfree.com/c/a/XML/Applying-XSLT-to-XML-Using-ASP.NET/2/ The tutorial shows how one converts xml
I am trying to sort xml document using XSLT version 1.0. My XML looks
Using XSLT transformation I want to convert an XML file, that in turn represents
I would like to transfrom xml file to another using php through xslt. On
i am trying to output the Form using XML & XSLT in php but
Im using http://www.ashberg.de/php-barcode/ scripts to generate a barcode. I now need to import the
I am using http://blog.frankel.ch/custom-loginmodule-in-tomcat tutorial for tomcat JAASRealm.I have added below in server.xml Realm

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.