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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:10:36+00:00 2026-06-15T23:10:36+00:00

What is the time complexity of the index access for the following XPath expression

  • 0

What is the time complexity of the index access for the following XPath expression in XSLT?

<xsl:value-of select="User[2]/username"/>
  1. O(log(n))
  2. O(1) or
  3. O(n)

I have a sorted xml-file with thousands of users which looks like this:

<Users>
  <User>
    <idPerson>460</idPerson>
    <username>a_aker01</username>
  </User>
  <User>
    <idPerson>677</idPerson>
    <username>a_aker02</username>
  </User>
  <User>
    <idPerson>1844</idPerson>
    <username>a_aker03</username>
  </User>
  <User>
    <idPerson>2373</idPerson>
    <username>a_aker04</username>
  </User>
</Users>

I am thinking of writing a binary search function in XSLT 2.0 (requiring a fast index access) for a faster search, because

<xsl:variable name="targetId" select="2373" />
<xsl:value-of select="User[idPerson=$targetId]/username"/>

is too slow for my needs. Does it perform a linear search?

  • 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-15T23:10:37+00:00Added an answer on June 15, 2026 at 11:10 pm

    The time-complexity of /Users/User[2] is implementation-specific. Most likely it will be an O(n) linear search, but perhaps there is an implementation out there that is smart enough to do it in O(1) under ideal conditions.

    However, why don’t you just use xsl:key instead of creating a binary search function? (This will work with XSLT 1.0 too.)

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
      <xsl:output method="text"/>
    
      <xsl:key name="user-for-idPerson" match="/Users/User" use="number(idPerson)"/>
    
      <xsl:template match="/">
        <xsl:variable name="targetId" select="2373" />
        <xsl:value-of select="key('user-for-idPerson', $targetId)/username"/>
      </xsl:template>
    
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is the time complexity of the Oracle MAX function O(1), O(log n) or O(n)
Wikipedia says the following on A*'s complexity: The time complexity of A* depends on
What is the time complexity of the following implemented algorithm? I should notice that
May I know why the time complexity of insertion of skip list is O(log
Simplex algorithm is said to have exponential worst case time complexity. Yet it is
What is the time complexity of the following loop? for(int i=1; i<=n; i=i*2){ System.out.println(*);
I need to calculate the time complexity of the following code: for (i =
Can an algorithm having a time complexity of O( n ) have a space
What is the time complexity of the following operations in java.util.TreeSet ? first() last()
What is the time complexity of this nifty function 'assoc'?

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.