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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:40:15+00:00 2026-06-01T02:40:15+00:00

I’m working on an assignment where i am supposed to display grocery items in

  • 0

I’m working on an assignment where i am supposed to display grocery items in different ways. I can’t seem to figure if the xsl file is wrong or the xml file, or both.

Snippet of assignment:
Every
item in the inventory should have a sale price, regardless of whether or not it is on sale. An item that is on sale will be identified through a sale attribute with values “yes” or “no”. The sale attribute should be placed in the ID tag. If the sale tag is “yes” then the sale price is used, otherwise the regular price is used.

My problem is that only the regular prices will display regardless whether @sale=”yes” or “no”

<body>
    <table> 
        <xsl:for-each select="catalog/item">            

                <tr>
                    <xsl:attribute name="sale">
                            <xsl:value-of select="id"/>
                        </xsl:attribute>
                    <td><xsl:value-of select="company"/></td>
                    <td><xsl:value-of select="product"/></td>
                    <td><xsl:value-of select="category"/></td>
                    <td><xsl:value-of select="description"/></td>
                    <xsl:choose>
                        <xsl:when test="@sale = 'yes'">
                            <td><xsl:value-of select="sale"/></td>
                        </xsl:when>
                        <xsl:otherwise>
                            <td><xsl:value-of select="price"/></td>
                        </xsl:otherwise>
                    </xsl:choose>
                    <td><xsl:value-of select="unit"/></td>
                    <td>
                        <img>
                            <xsl:attribute name="src">
                                <xsl:value-of select="picture"/>
                            </xsl:attribute>
                    </img>
                    </td>
                </tr>

        </xsl:for-each>
    </table>
</body>

and the XML with sample of 2 items:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="sale.xsl" xsl:import href="company.xsl" xsl:import href="category.xsl"?>

<!DOCTYPE catalog SYSTEM "stock.dtd">

<catalog>
<item>
    <id sale="yes">801</id>
    <company>Grocery Gateway</company>  
    <product>Organic Strawberries</product> 
    <category>Produce</category>    
    <description>Fresh and organic strawberries imported from U.S.A. This product is subject to availability</description>  
    <price>5.99</price>
    <sale>4.99</sale>
    <unit>454g</unit>
    <picture>pics/M6548[1].jpg</picture>
</item>
<item>
    <id sale="no">101</id>
    <company>Nestle </company>  
    <product>Pure Life Spring Water</product>   
    <category>Beverages</category>  
    <description>Ingredients are spring water, and ozone. </description>    
    <price>5.99</price>
    <sale>4.99</sale>
    <unit>24x500mL</unit>
    <picture>pics/M58629[1].jpg</picture>
</item></catalog> 
  • 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-01T02:40:17+00:00Added an answer on June 1, 2026 at 2:40 am

    The reason why it’s not displaying the sale price properly is because you’re referencing the @sale attribute incorrectly.

    <xsl:when test="@sale = 'yes'">
    

    The above tries to look for an attribute called sale on the current for-each iteration (in this case being catalog/item, but the attribute doesn’t exist on this node in your XML). You’ll need to explicitly say that you’re looking for it on the id node, like so :

    <xsl:when test="id/@sale = 'yes'">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my XML file chapters tag has more chapter tag.i need to display chapters
i want to parse a xhtml file and display in UITableView. what is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.