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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:00:42+00:00 2026-05-27T17:00:42+00:00

I have a simple HTML input file; which contains a table. The column headers

  • 0

I have a simple HTML input file; which contains a table.
The column headers of the HTML table are defined in row 2; and the data follows for row 2+.

So I’m picking up the data like this:

<xsl:template match="HTML">
    <xsl:apply-templates select="//TABLE/TR[position() > 2]"/>
</xsl:template>

<xsl:template match="TR">
    <xsl:apply-templates select="TD"/>
</xsl:template>



   <xsl:template match="TD">
    <xsl:variable name="pos"><xsl:value-of select="position()"/></xsl:variable>
    <xsl:value-of select="normalize-space(.)"/>
        <xsl:text>&#10;</xsl:text>
        <xsl:value-of select="/HTML//TABLE/TR[2]/TD[$pos]"/>
    </xsl:template>

(This last template is a debug version; the final output I’m after is to use the header information to generate dynamic attribute names)

What I’m struggling to get, is the $pos variable to index the TR[2] on the document: it always seems to equate to ‘1’; originally I just trying using ‘position()’ and the index, but this doesn’t work for me.

I know (if I do an ‘xsl:value-of’) that $pos is correctly changing, but within the predicate it seems to collapse into a 1 ….

What do I need to do here….

  • 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-27T17:00:43+00:00Added an answer on May 27, 2026 at 5:00 pm

    The problem is here:

    /HTML//TABLE/TR[2]/TD[$pos]
    

    In XPath it must be known that $x is a number and only then someElement[$x] is treated as a shortcut to someElement[position() = $x]

    In XSLT 1.0 / XPath 1.0 there is only rudimentary, weak typing and the type of a variable cannot be specified and isn’t generally known.

    This is why, this XPath expression:

    /HTML//TABLE/TR[2]/TD[$pos]
    

    is interpreted as:

    /HTML//TABLE/TR[2]/TD[boolean($pos)]
    

    and selects all TD elements that are children of the TR element that is the second TR child of any TABLE element that is a descendant of the top element of the XML document.

    Solution:

    In XPath 1.0 use either the full unabbreviated expression:

    /HTML//TABLE/TR[2]/TD[position() = $pos]
    

    or use the shorter:

    /HTML//TABLE/TR[2]/TD[number($pos)]
    

    In XPath 2.0 (XSLT 2.0), explicitly specify the type of the variable:

    <xsl:variable name="pos" as="xs:integer" select="position()"/>
    

    and then it can be used and correctly known to be an xs:integer in:

    /HTML//TABLE/TR[2]/TD[$pos]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to have a simple html table, that highlights a row as a
I have a simple form with some plain html input like bellow using ASP.NET
I have a simple HTML Table (10 columns x 500 rows). When the page
I have a simple html file with the code below. It calls submitform.php. But
I have this html form which calls a php file . The index.html ->
I have three simple html or php file that I'm going to create. What
I have a PHP page which generates an HTML table. At the bottom of
I have an HTML, PHP - Jquery form. The last input is a file
I have simple HTML code with some JavaScript. It looks like: <html> <head> <script
I have a simple HTML. I am using the JQuery for AJAX purpose. Now,

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.