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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:40:55+00:00 2026-06-16T09:40:55+00:00

I have an XML file with the following structure: <block1> <node> <name>A<name/> <node/> <node>

  • 0

I have an XML file with the following structure:

<block1>
 <node>
  <name>A<name/>
 <node/>
 <node>
  <name>B<name/>
 <node/>
 ...
</block1>

<block2>
 <node>
  <name>B<name/>
 <node/>
 <node>
  <name>D<name/>
 <node/>
 ...
</block2>

The entrees of each block are sorted based on the name.

I want to create a table that will hold all of the names that belong in block1 and block2.
How can I do this efficiently (using the fact that the nodes are sorted)?

  • 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-16T09:40:56+00:00Added an answer on June 16, 2026 at 9:40 am

    A solution using keys:

    <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="kB1NodeByVal" match="block1/node" use="name"/>
     <xsl:key name="kB2NodeByVal" match="block2/node" use="name"/>
    
     <xsl:variable name="vDistinctB1Nodes" select=
     "/*/block1/node
          [generate-id()
          =
           generate-id(key('kB1NodeByVal',name)[1])
           ]"/>
    
     <xsl:template match="/">
         <xsl:copy-of select="$vDistinctB1Nodes[key('kB2NodeByVal', name)]"/>
     </xsl:template>
    </xsl:stylesheet>
    

    When this transformation is applied on the (corrected from severe malformedness) provided XML document:

    <t>
        <block1>
            <node>
                <name>A</name>
            </node>
            <node>
                <name>B</name>
            </node>
     ...
        </block1>
        <block2>
            <node>
                <name>B</name>
            </node>
            <node>
                <name>D</name>
            </node>
     ...
        </block2>
    </t>
    

    the wanted, correct result is produced:

    <node>
       <name>B</name>
    </node>
    

    The efficiency of this solution is O(k), where k is the number of distinct values in Set 1. This assumes that we have already constructed the keys (indexes) and the set of distinct values in Set 1.

    • 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 in the following structure. <NewDataSet> <markers> <name>name text</name> <desc>desc
I have an XML file with the following structure: <Products> <Product name=MyProduct1> <Components> <Component
I have an xml file with following structure: <table name=tblcats> <row> <Id>3680</Id> <Industry>Associations</Industry> <ParentId>1810</ParentId>
I have an xml file with following structure: <table name=tblcats> <row> <Id>3680</Id> <Industry>Associations</Industry> <ParentId>1810</ParentId>
I have an XML file with the following structure: <Definitions> <Definition Execution=Firstkey Name=Somevalue></Definition> <Definition
ich have a xml file with the following structure: <layer1 name=this is layer1> <messages>
I have an XML file of the following structure <Root> <Child Name=First> <Data Name=a
I have an xml file with the following structure: <main_tag> <first> <tag1>val1</tag1> <conf> <tag2>val2</tag2>
I have a large xml file (approx. 10 MB) in following simple structure: <Errors>
I have the following XML File: <persons> <person name=shawn> <age>34</age> <hair style=spikes>red</hair> </person> <person

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.