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

  • Home
  • SEARCH
  • 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 3399536
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:46:59+00:00 2026-05-18T04:46:59+00:00

I have a list of terms in xml. Terms either have termtype nd or

  • 0

I have a list of terms in xml. Terms either have termtype nd or pt. If a term is termtype nd, it has no ID, but instead references a termtype PT which does have an ID. I need to do two things.

  1. replace the XXX for termId value with an incremental number for termtype nd, so all terms have an id.

  2. where a termType ND references a termType PT, I need to somehow look for its ID and insert it:


<Zthes>
<term>
<termName>Term 1</termName>
<termId>insert new term id N+1 </termId>
<termType>Nd</termType>

 <relation>
 <relationType>USE</relationType>
 <termId>insert ID of term 2 <termID>
<termName>Term2</termName>
 </relation>
</term>

<term>
<termName>Term 2</termName>
<termId>587889</termId>
<termType>pt</termType>
 </term>

</zthes>

Could anyone give me pointers on how to do this. I don’t know anything about xslt. I’ve looked on here and found stuff about find and replace with Unique but from what I understand of the answer, I don’t think it is applicable.

ALso, It doesn’t have to be xslt. I work with a developer who said that this was the best way to do this, but that the answer was too trivial for him to bother with. Its too difficult for me though!

  • 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-18T04:47:00+00:00Added an answer on May 18, 2026 at 4:47 am

    This single transformation:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:key name="ktermPtIdByName"
          match="term[termType='pt']/termId"
          use="../termName"/>
    
     <xsl:template match="node()|@*">
         <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
         </xsl:copy>
     </xsl:template>
    
     <xsl:template match="term[termType='Nd']/termId">
      <termId>
        <xsl:number level="single" count="/*/term[termType='Nd']"/>
      </termId>
     </xsl:template>
    
     <xsl:template match="relation/termId">
      <termId>
        <xsl:value-of select="key('ktermPtIdByName', ../termName)"/>
      </termId>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on the following XML document (your XML but corrected to be syntactically well-formed and semantically correct, then enlarged twice to be made more interesting):

    <zthes>
        <term>
            <termName>Term 1</termName>
            <termId></termId>
            <termType>Nd</termType>
            <relation>
                <relationType>USE</relationType>
                <termId></termId>
                <termName>Term 2</termName>
            </relation>
        </term>
        <term>
            <termName>Term 2</termName>
            <termId>587889</termId>
            <termType>pt</termType>
        </term>
        <term>
            <termName>Term 3</termName>
            <termId></termId>
            <termType>Nd</termType>
            <relation>
                <relationType>USE</relationType>
                <termId></termId>
                <termName>Term 4</termName>
            </relation>
        </term>
        <term>
            <termName>Term 4</termName>
            <termId>587890</termId>
            <termType>pt</termType>
        </term>
    </zthes>
    

    produces the wanted, correct result:

    <zthes>
       <term>
          <termName>Term 1</termName>
          <termId>1</termId>
          <termType>Nd</termType>
          <relation>
             <relationType>USE</relationType>
             <termId>587889</termId>
             <termName>Term 2</termName>
          </relation>
       </term>
       <term>
          <termName>Term 2</termName>
          <termId>587889</termId>
          <termType>pt</termType>
       </term>
       <term>
          <termName>Term 3</termName>
          <termId>2</termId>
          <termType>Nd</termType>
          <relation>
             <relationType>USE</relationType>
             <termId>587890</termId>
             <termName>Term 4</termName>
          </relation>
       </term>
       <term>
          <termName>Term 4</termName>
          <termId>587890</termId>
          <termType>pt</termType>
       </term>
    </zthes>
    

    Do note:

    1. The identity rule is used to copy every node “as-is”.

    2. Templates override the identity rule only for elements that need to be modified.

    3. <xsl:number> is used for (me being lazy) calculating the required termId.

    4. A key is used for most efficient finding a termId by its TermName

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have list of files which contain particular patterns, but those files have been
I have a list of strings which has been sorted by a specific comparison
I have a list of words, with patterns either term or termNUM, e.g. term
I have a list with numerous Items. I want to search for a term
I have List I want to sort Desc by Priority, which is int and
I have List objects which are shown like this: www.mysite.com/lists/123 Where 123 is the
I have list of catalog paths and need to filter out some of them.
There's an XML stream which I need to parse. Since I only need to
I have a list of URLs and I need to display the Google search
I have read through the documentation for Winsock2 on MSDN, but I still need

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.