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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:34:40+00:00 2026-06-07T01:34:40+00:00

I have an xml file which looks like this: <section> <title> title of section

  • 0

I have an xml file which looks like this:

<section>
  <title> title of section </title>
  <table>
     <title> title of table</title>
     <tableData columns = 2>
     <column width ="50"/>
     <column width ="100"/>
     <tableHead>
        <row>
             <entry>column 1</entry>
        </row> 
        <row>
             <entry>column 2</entry>
        </row>
     </tableHead>
     <tableBody>
       <row>
             <entry>text</entry>
             <entry>abc</entry>
       </row> 
       <row>
             <entry>text</entry>
             <entry>dbe</entry>
      </row> 
       <row>
             <entry>text</entry>
             <entry>fgh</entry>
       </row> 
     </tableBody>
   </table>
 </section>

I need to process each entry in tableHead/row/entry and spit it out in some format that also includes the columnWidth. So, my output must look like
{“name”:”column 1″, “width”:”50px”},{“name”:”column 2″, “width”:”100px”}

My transform looks like this

 <xsl:template match="//table/tableHead/row/entry">
    <xsl:text>{"name": "</xsl:text><xsl:value-of select"."/>
    <xsl:text>", "width":"</xsl:text>

    <xsl:call-template name="get_column_width">
       <xsl:with-param name ="rowNum">
          <xsl:value-of sellect"position()"/>
       </xsl:with-param>
    </xsl:call-template>
  </xsl:template>


 <xsl:template name ="get_column_width">
     <xsl:param-name="rowNum">
     <xsl:value-of select="../../../columnWidth[$rowNum]/@width"/>
     <xsl:text>px"}</xsl:text>
 </xsl:template>

Strangely, this produces {“name”:”column 1″, “width”:”50 100px”},{“name”:”column 2″, “width”:”50 100px”}

However, when I output only the rowNum parameter I get exactly what I expect:

{“name”:”column 1″, “width”:1px”},{“name”:”column 2″, “width”:”2px”}

So, rowNum is 1 and 2 so the select statement will use columnWidth[1] and columnWidth[2], but for whatever reason it just outputs both of them. I tried using columnWidth[1] in the select and it outputs 50 as I would expect. columnWidth[2] outputs 100. I’m really confused here. Using preceding-sibling gave the same result. Is there something wrong with my template matching?

Unfortunately changing the xml format is not an option.

  • 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-07T01:34:42+00:00Added an answer on June 7, 2026 at 1:34 am

    Instead of:

    <xsl:value-of select="../../../columnWidth[$rowNum]/@width"/>
    

    Use:

    <xsl:value-of select="../../../columnWidth[position() = $rowNum]/@width"/>
    

    Explanation

    In XPath:

    someExpression[someInteger]
    

    is a shorthand for:

    someExpression[position() = someInteger]
    

    However, in case of:

    someExpression[$someVariableReference]
    

    the XPath 1.0 processor typically doesn’t know what value and of what type is contained in the variable. Therefore, it converts this variable to a boolean value (true() or false()) to perform the complete evaluation.

    By definition:

    boolean(someNumber)
    

    is equivalent to:

    not(somenumber = 0)
    

    As neither of the numbers 1 and 2 is zero, the predicate [$rowNum] is true() in both cases,

    Thus:

    ../../../columnWidth[$rowNum]/@width
    

    selects the width attributes of both columnWidth elements.

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

Sidebar

Related Questions

I have XML file which looks like this: <?xml version=1.0?> <results> <row id=100><name>name blah</name></row>
I have an XML file generated using javax.sql.rowset.WebRowSet.writeXml which looks like: <metadata> This section
I have an XML file which looks like this : <?xml version=1.0 encoding=UTF-8?> <resultset
Say I have an XML file which looks like this: <?xml version=1.0 encoding=UTF-8?> <Project
I have an XML file, part of which looks like this: <wave waveID=1> <well
I have an xml file which looks like this <?xml version=1.0 encoding=UTF-8 ?> <BulkDataExchangeRequests
I have a XML sitemap file which looks like this <?xml version=1.0 encoding=UTF-8 ?>
I have a sample xml file which looks like the one below: <Root> <SubOne>
I have an XML file which has many section like the one below: <Operations>
I'm trying to read in an xml file which looks like this <?xml version=1.0

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.