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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:24:43+00:00 2026-05-26T16:24:43+00:00

Below is my XML file, which is used to stored the data – <Locations>

  • 0

Below is my XML file, which is used to stored the data –

<Locations>
   <location>
      <place>Newyork</place>
      <dt>01-Dec-2011</dt>
   </location>
   <location>
      <place>Berlin</place>
      <dt>02-Dec-2011</dt>
   </location>
   <location>
      <place>Tokyo</place>
      <dt>04-Dec-2011</dt>
   </location>
</Location>

What I want to achieve is –

I want to replace the <dt> tags date value, if the visit is re-scheduled. For example-
If the visit date for Berlin is changed, stored in <dt> tags, then how to edit/replace the same
in the XML file using XSLT..? Thanks in advance – John

  • 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-26T16:24:44+00:00Added an answer on May 26, 2026 at 4:24 pm

    This transformation shows how to use a global parameter (modelled here with an inline element) to specify (possibly multiple) updates:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:my="my:my" >
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <my:updates>
      <update place="Berlin" dt="11-Dec-2011"/>
     </my:updates>
    
     <xsl:template match="node()|@*">
         <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
         </xsl:copy>
     </xsl:template>
    
     <xsl:template match=
      "location
         [place = document('')/*/my:updates/update/@place]
           /dt/text()
      ">
      <xsl:value-of select=
        "document('')/*/my:updates/update
                          [@place = current()/../../place]
                            /@dt
        "/>
     </xsl:template>
    </xsl:stylesheet>
    

    When applied on the provided XML document (corrected to make it well-formed):

    <Locations>
       <location>
          <place>Newyork</place>
          <dt>01-Dec-2011</dt>
       </location>
       <location>
          <place>Berlin</place>
          <dt>02-Dec-2011</dt>
       </location>
       <location>
          <place>Tokyo</place>
          <dt>04-Dec-2011</dt>
       </location>
    </Locations>
    

    the wanted, correct result is produced:

    <Locations>
       <location>
          <place>Newyork</place>
          <dt>01-Dec-2011</dt>
       </location>
       <location>
          <place>Berlin</place>
          <dt>11-Dec-2011</dt>
       </location>
       <location>
          <place>Tokyo</place>
          <dt>04-Dec-2011</dt>
       </location>
    </Locations>
    

    Explanation:

    1. The identity rule copies every node “as-is“.

    2. There is just one overriding template — matching the text-node child of any dt whose place sibling’s string value has a corresponding my:updates/update element. In this template we output the value of the dt attribute of this corresponding my:updates/update element.

    Do note: In a realworld transformation the inline my:updates element will be better replaced by an external, global parameter. Read your XSLT processor’s documentation how to pass an external parameter to the transformation — this is implementation-dependent.

    UPDATE: As the OP has found it difficult to convert this solution to one using global, externally passed xsl:param, here is this converted solution:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:ext="http://exslt.org/common">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:param name="pUpdates">
      <update place="Berlin" dt="11-Dec-2011"/>
     </xsl:param>
    
     <xsl:variable name="vUpdates" select=
         "ext:node-set($pUpdates)/*"/>
    
     <xsl:template match="node()|@*">
         <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
         </xsl:copy>
     </xsl:template>
    
     <xsl:template match="dt/text()">
      <xsl:choose>
          <xsl:when test="../../place=$vUpdates/@place">
           <xsl:value-of select=
               "$vUpdates[@place = current()/../../place]/@dt"/>
          </xsl:when>
          <xsl:otherwise>
           <xsl:value-of select="."/>
          </xsl:otherwise>
      </xsl:choose>
     </xsl:template>
    </xsl:stylesheet>
    

    When this transformation is applied on the same XML document (above), the same correct and wanted result is produced:

    <Locations>
       <location>
          <place>Newyork</place>
          <dt>01-Dec-2011</dt>
       </location>
       <location>
          <place>Berlin</place>
          <dt>11-Dec-2011</dt>
       </location>
       <location>
          <place>Tokyo</place>
          <dt>04-Dec-2011</dt>
       </location>
    </Locations>
    

    Do note: In this solution the xsl:param still has its value hardcoded and this is the only reason we are using the ext:node-set() extension function. If the parameter is really passed from outside, then this convertion from RTF to a regular tree isn’t necessary and the parameter should be referenced directly.

    Also, in XSLT 1.0 we have to match more inexactly and to use comparisons (the xsl:choose) inside the body of the template. This is so because in XSLT 1.0 it isn’t allowed to reference variables/parameters inside the match-pattern.

    In XSLT 2.0 this limitation has been eliminated, so we can just have a much simpler transformation:

    <xsl:stylesheet version="2.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:param name="pUpdates">
      <update place="Berlin" dt="11-Dec-2011"/>
     </xsl:param>
    
     <xsl:template match="node()|@*">
         <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
         </xsl:copy>
     </xsl:template>
    
     <xsl:template match=
       "location[place=$pUpdates/*/@place]/dt/text()">
           <xsl:value-of select=
               "$pUpdates/*[@place = current()/../../place]/@dt"/>
     </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 an XML file which has many section like the one below: <Operations>
Below is an excerpt from an .svg file (which is xml): <text xml:space=preserve style=font-size:14.19380379px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;font-family:DejaVu
I have a bit of xml file named Sample.xml which is shown below <?xml
I have two XML file sitemap.xml and mouse.xml which look like below.Here the thing
I have a file list as given below which is used by an existing
I have an xml file which looks like the below example <Ids> <Id> <set>ai</set>
I have an xml file like below which I will use to set background
I've got a XML Schema (xsd file) snippet bellow, in which I want the
How to read the below xml file and write its content into a plain
I already implemented to create the XML file below with XmlTextWriter when application initialization.

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.