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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:11:07+00:00 2026-06-06T20:11:07+00:00

I’ve got some routines in an XSLT stylesheet that process an XML file to

  • 0

I’ve got some routines in an XSLT stylesheet that process an XML file to display a product to a user in a web page (ASP.NET). The XSLT stylesheet outputs an html to display the product as well as any variations of the product, such as size, color, package quantity, style, etc.

The variations are handled as arbitrary. None of my code actually refers to the variations specifically. The XML always contains a node tree of variations that the product can have. Then each product includes these variations. For example, in the XML:

<Variations>
    <Variation>
        <Name>Color</Name>
    </Variation>
    <Variation>
        <Name>Size</Name>
    </Variation>
</Variations>

From this information I know to create two controls. One to provide Color selection, the other to provide Size selection.

Each variation of the product is listed in the XML in its own node. It has a unique product ID – different from all the other product variations. For example:

<Product>
    <ID>000001</ID
    <VariationAttribute>
        <Name>Color</Name>
        <Value>Green</Value
    </VariationAttribute>
    <VariationAttribute>
        <Name>Size</Name>
        <Value>6</Value>
    </VariationAttribute>
</Product>
<Product>
    <ID>000002</ID
    <VariationAttribute>
        <Name>Color</Name>
        <Value>Multiple(orange)</Value
    </VariationAttribute>
    <VariationAttribute>
        <Name>Size</Name>
        <Value>6</Value>
    </VariationAttribute>
</Product>

In my XSLT I create a unique list of all possible values of an attribute. For example, many of the products have a color of green, but in different sizes. Many of the products have a size of 6, but in different colors. So I do a unique sort on each attribute and create DropDownLists in my XSLT.

Now I needed a way of allowing the user to add an item to their shopping cart. This would require knowing the product ID, and so my XSLT also creates a few JSON objects. One of the objects contains the possible variation attributes and the name (ID) of the control that provides selection of the attribute options, like this:

var propCtlMap = [{"Color": "ddColor","Size": "ddSize"}]

Another JSON object contains a list of all the possible product configurations, like this:

var datalist = [
{"pID": "000001","Color": "Green","Size": "6"},
{"pID": "000002","Color": "Multiple(orange)","Size": "6"},
{"pID": "000003","Color": "Multiple(purple)","Size": "6"},
{"pID": "000004","Color": "Multiple(red)","Size": "6"},
{"pID": "000005","Color": "Purple","Size": "6"},
{"pID": "000006","Color": "Green","Size": "8"},
{"pID": "000007","Color": "Multiple(orange)","Size": "8"},
{"pID": "000008","Color": "Multiple(purple)","Size": "8"},
{"pID": "000009","Color": "Multiple(red)","Size": "8"},
{"pID": "000010","Color": "Purple","Size": "10"},
etc, etc
]

So far, I have all of this working. I’ve got JQuery events that handle a DropDownList .change. Then map all of the selected variation options to a product ID. This allows me to include a product ID in a hidden field so that when the user clicks the “Add to Cart” button, their choices are handled. Again, all this works fine.

Now to my specific question… I want to be able to disable variation options that are not available/not in stock. I know it’s possible to disable a selection in a DropDownList. I’ve got code for that written in ASP. I think I can convert it to JQuery, but what I don’t know how to do is determine (from datalist above, in JQuery) which options are not available. In datalist above, there are 3 possible sizes – 6, 8 and 10. Green is available in sizes 6 and 8, but not in 10. Likewise, purple is available in size 10, but not in 6 or 8.

I’m thinking there must be some method/function using JQuery/Javascript that can help me make a matrix of all the options so I can disable ones that aren’t valid. In the example above, if a user selected Purple, I’ll want a list of all sizes available in that color. Likewise, if a user selected size 8, I want a list of all colors available in that size.

I think if I knew how to get these lists I could handle most the rest of the coding.

Btw, I’ve only been learning JQuery/Javascript for about 2 weeks now. I know very little but am catching on.

Thanks.

  • 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-06T20:11:07+00:00Added an answer on June 6, 2026 at 8:11 pm

    You can use jQuery’s grep function to filter your array:

    var objectArray = JSON.parse(json);
    
    var purpleElements = $.grep(objectArray, function (element, index) {
        // purpleElements will contain all of those values in objectArray for which
        // this function returns true.
        return element.Color === "Purple";
    });
    
    $.each(purpleElements, function (index, element) {
        alert(element.Color + ": " + element.Size);
    });
    

    Will alert: Purple: 6, Purple: 10.

    If you just wanted a list of Sizes you could then use jQuery’s map function to transform the array:

    var sizes = $.map(purpleElements, function (element, index) {
        // sizes will contain an array of the return values of this function
        // for each element in purpleElements.
        return element.Size;
    });
    
    $.each(sizes, function (index, element) {
        alert(element);
    });
    

    Will alert 6, 10.

    See this jsFiddle.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
In my XML file chapters tag has more chapter tag.i need to display chapters
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i want to parse a xhtml file and display in UITableView. what is the
I'm parsing an XML file, the creators of it stuck in a bunch social
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.