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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:14:14+00:00 2026-06-04T22:14:14+00:00

I am trying to merge the elements from two separate web.xml files using XSLT.

  • 0

I am trying to merge the elements from two separate web.xml files using XSLT. For example, if web-1.xml and web-2.xml are being merged, and I’m processing web-1.xml, I want all elements in web-2.xml to be added into the result, except any that already exist in web-1.xml.

In the XSLT sheet, I have loaded the document whose servlet’s are to be merged into the other document using:

<xsl:variable name="jandy" select="document('web-2.xml')"/>

I then have the following rule:

<xsl:template match="webapp:web-app">
  <xsl:copy>
    <!--  Copy all of the existing content from the document being processed  -->
    <xsl:apply-templates/>      

    <!--  Merge any <servlet> elements that don't already exist into the result  -->        
    <xsl:for-each select="$jandy/webapp:web-app/webapp:servlet">
      <xsl:variable name="servlet-name"><xsl:value-of select="webapp:servlet-name"/></xsl:variable>

      <xsl:if test="not(/webapp:web-app/webapp:servlet/webapp:servlet-name[text() = $servlet-name])">
        <xsl:copy-of select="."/>
      </xsl:if>
    </xsl:for-each>

  </xsl:copy>

</xsl:template>

The problem I’m having is getting the test in the if correct. With the above code, the test always evaluates to false, whether a servlet-name element with the given node exists or not. I have tried all kinds of different tests but with no luck.

The relevant files are available at http://www.cs.hope.edu/~mcfall/stackoverflow/web-1.xml, and http://www.cs.hope.edu/~mcfall/stackoverflow/transform.xslt (the second web-2.xml is there as well, but StackOverflow won’t let me post three links).

  • 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-04T22:14:16+00:00Added an answer on June 4, 2026 at 10:14 pm

    provide an anchor for the first document, just before the for-each loop:

    <xsl:variable name="var" select="."/>
    

    then, use it in your if:

    <xsl:if test="not($var/webapp:servlet/webapp:servlet-name[text() = $servlet-name])">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using XSLT for converting a XML derived from web and convert the
I'm trying to merge two docx-documents into one docx-document using OpenXML SDK 2.0. The
I am trying to merge multiple excel files using DataTable.Merge() option For Each fileName
I am trying to merge the result of two separate MDX queries, where the
I am trying to merge many xml files into one. I have successfully done
I'm trying to merge two arrays for the values of array1 that are set
I am trying to merge two data.frames together, based on a common column name
I'm trying to merge (append) 3 videos using AVAssetExportSession, but I keep getting this
I'm trying to do an svn merge of a change from trunk onto a
I am trying to merge two list in parallel. I have two sorted lists

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.