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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:07:16+00:00 2026-05-26T11:07:16+00:00

yet another class take-home quiz I need help with to compare the position() return

  • 0

yet another class take-home quiz I need help with to compare the position() return value against a parameter value as follows using XSLT 1.0. I have this simple XML below…

<Providers>
    <Company>
        <Name>Alpha</Name>
    </Company>

    <Company>
        <Name>Beta</Name>
    </Company>

    <Company>
        <Name>Omega</Name>
    </Company>
</Providers>

And I want to pass in a parameter with a numeric value designating which node level to insert a new element called Rating like this…

<Providers>
        <Company>
                <Name>Alpha</Name>
        </Company>

        <Company>
                <Name>Beta</Name>
                <Rating>Good</Rating>
        </Company>

        <Company>
                <Name>Omega</Name>
        </Company>
</Providers>

Here’s my XSLT…

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output indent="yes"/>
  <xsl:strip-space elements="*"/>

<xsl:param name="nodeNumber">2</xsl:param>


<xsl:template match="*">
    <xsl:copy>
        <xsl:copy-of select="@*|node()"/>
    </xsl:copy>
</xsl:template>


<xsl:template match="Providers">
    <xsl:copy>
      <xsl:apply-templates />
    </xsl:copy>
</xsl:template>


<xsl:template match="Company[ position() = 2 ]">
    <xsl:copy>
        <xsl:copy-of select="@*|node()"/>
        <Rating>Good</Rating>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>

Instead of hard-coding to the second node…

<xsl:template match="Company[ position() = 2 ]">

I want to do a comparison like this so it uses a parameter value…

<xsl:template match="Company[ position() = $nodeNumber ]">

but I get an error if XSLT is 1.0…

c:\ msxsl.exe providers.xml providers.xsl

Error occurred while compiling stylesheet 'providers.xsl'.

Code:   0x80004005
Variables may not be used within this expression.

Company[ position() = -->$nodeNumber <--]

it works fine if XSLT is 2.0…

c:\ altovaxml.exe /xslt2 providers.xsl /in providers.xml

<?xml version="1.0" encoding="UTF-8"?>
<Providers>
        <Company>
                <Name>Verizon</Name>
        </Company>
        <Company>
                <Name>Sprint</Name>
                <Rating>Good</Rating>
        </Company>
        <Company>
                <Name>ATT</Name>
        </Company>
</Providers>

I need to use XSLT 1.0. Thank you very much for your time and effort…

  • 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-26T11:07:17+00:00Added an answer on May 26, 2026 at 11:07 am
    <xsl:template match="Company">
       <xsl:copy>
         <xsl:copy-of select="@*|node()"/>
         <xsl:if test="(count(preceding-sibling::Company) + 1) = $nodeNumber">
            <Rating>Good</Rating>
         </xsl:if>
        </xsl:copy>
    </xsl:template>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yet another TFrame IDE-registered-component question from me. Thanks for all the help, fellow programmers.
Yet another argument with a friend of mine. Consider this code: class User <
While writing yet another class full of methods that access database tables to work,
This is yet another of my Java questions. Please take a look at this
Yet another newbie with ASP.NET MVC! All I intend to do is for a
I've just added yet another 3rd-party component to my .net project that contains a
I was handling yet another KeyDown event in a user control when I wondered
I don't want to open another Yet Another Js VS Js thread. I guess,
After getting a helpful answer here , I have run into yet another problem:
I guess this question will sound familiar, but I am yet another programmer baffled

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.