iteration

Iteration, or copying in XSL, based on a count. How do I do it?

I'm trying to create an inventory list (tab-delimited text, for the output) from XML data. The catch is, I need to take the line that I created, and list it multiple times (iterate ???), based on a number found in the XML. So, from the XML below: <?xml version="1.0" encoding="UTF-8"?> <library> <aisle label="AA"> <row>bb</row> ...

Check if checkboxes are selected on page load and add a class to parent html li

Im looking a way to do it with prototype, this js, needs to loads with the page and interate over all the elements (inputs - checkboxes, in this case) with the given id and assign a class to its parent <li></li> The JS is: function changeSelectionStyle(id) { var inputId = id.substr(0,id.length-2); if(document.getElementById(inputId)...

How to print element values when iterating through XML document in PHP

I am iterating through the results of a service call to yahoo news thus: //Send service request if (!$yahooResults = file_get_contents($yahooRequest)) { echo 'Error processing service request'; } //Read result into xml document $yahooResultXml = new DOMDocument('1.0', 'UTF-8'); $yahooResultXml->loadXML($y...

Replace string with incremented value

Hello, I'm trying to write a CSS parser to automatically dispatch URLs in background images to different subdomains in order to parallelize downloads. Basically, I want to replace things like url(/assets/some-background-image.png) with url(http://assets[increment].domain.com/assets/some-background-image.png) I'm using this insid...

How Do I Add Value To All Previous Values In Array

Lets say I have the following array: my_array = [1, 5, 8, 11, -6] I need to iterate over this array and add the values prior to the current value together. An example will probably be easier to understand. I need to return an array that should look something like this: final_array = [1, 6, 14, 25, 19] I have tried doing something ...

f# iterating over two arrays, using function from a c# library

I have a list of words and a list of associated part of speech tags. I want to iterate over both, simultaneously (matched index) using each indexed tuple as input to a .NET function. Is this the best way (it works, but doesn't feel natural to me): let taggingModel = SeqLabeler.loadModel(lthPath + "models\penn_00_1...

How do I return the value of the owner and id attributes respectively from an XML result set using PHP?

I am using PHP to iterate over the following result set, the aim is to build a hyperlink for each result using a foreach loop. I have stored the XML result in $images, and have constructed this loop: foreach ($images as $image) { //Build link to each photo returned //base URL $flickrPhotoUrl = 'http://www.flickr.com/photos/'; ...

Count Upwards for ID jQuery

Hi Guys, I have the following HTML structure <div id="test-1-yay"></div> ... bunch of code ... <div id="test-2-yay"></div> ... bunch of code ... <div id="test-3-yay"></div> I was wondering how I can use jQuery to basically identify each of these "id's" and then apply some jQuery to them ? I'm new to this so little unsure ? Something ...

Saving WorkItem#IterationPath on newly created Iteration

I can successfully create an iteration via: However, when I try and assign this path to a work item and save it the field doesn't validate. If I run the tests again (with the iteration already created) the same code succeeds. Does anybody know how to make this work? ...

for x in y, type iteration in python. Can I find out what iteration I'm currently on?

Hi, I have a question about the loop construct in Python in the form of: for x in y: In my case y is a line read from a file and x is separate characters. I would like to put a space after every pair of characters in the output, like this: aa bb cc dd etc. So, I would like to know the current iteration. Is it possible, or do I need to u...

C++ STL: How to iterate vector while requiring access to element and its index?

I frequently find myself requiring to iterate over STL vectors. While I am doing this I require access to both the vector element and its index. I used to do this as: typedef std::vector<Foo> FooVec; typedef FooVec::iterator FooVecIter; FooVec fooVec; int index = 0; for (FooVecIter i = fooVec.begin(); i != fooVec.end(); ++i, ++index) ...

Why does Python's 'for ... in' work differently on a list of values vs. a list of dictionaries?

I'm wondering about some details of how for ... in works in Python. My understanding is for var in iterable on each iteration creates a variable, var, bound to the current value of iterable. So, if you do for c in cows; c = cows[whatever], but changing c within the loop does not affect the original value. However, it seems to work diffe...

Feedback on iterating over type-safe enums

In response to the earlier SO question "Enumerate over an enum in C++", I came up with the following reusable solution that uses type-safe enum idiom. I'm just curious to see the community feedback on my solution. This solution makes use of a static array, which is populated using type-safe enum objects before first use. Iteration over e...

Is map/collection order stable between calls?

If I have a hash map and iterate over the objects repeatedly, is it correct that I'm not guaranteed the same order for every call? For example, could the following print two lines that differ from each other: Map<String,Integer> map = new HashMap<String,Integer>() {{ put("a", 1); put("b", 2); put("c", 3); }}; System.out.println(map); ...

How to stop Python from adding whitespace while iterating?

My Python code: mapArray = [["#","#","#"],["#","#","#"],["#","#","#"]] for row in mapArray: for cell in row: print cell, print print prints this: # # # # # # # # # why not this: ### ### ### Thanks much! ...

Is safe ( documented behaviour? ) to delete the domain of an iterator in execution

I wanted to know if is safe ( documented behaviour? ) to delete the domain space of an iterator in execution in Python. Consider the code: import os import sys sampleSpace = [ x*x for x in range( 7 ) ] print sampleSpace for dx in sampleSpace: print str( dx ) if dx == 1: del sampleSpace[ 1 ] del sampleSpace...

Is an iteration on a F# map or set in-order traversal?

AFAIK, F# Map and set are implemented as red-black trees, so I guess that an iteration on these would be in-order traversal. I did some test and the iteration results are always sorted. But I want to make it sure. Is it in-order traversal? ...

JSTL - Using forEach to iterate over a user-defined class

What methods do I need to add to a custom Java class so that I can iterate over the items in one of its members? I couldn't find any specifications about how the JSTL forEach tag actually works so I'm not sure how to implement this. For example, if I made a generic "ProjectSet" class and I woud like to use the following markup in the JS...

How do I loop through a Python list by twos?

Possible Duplicate: What is the most pythonic way to iterate over a list in chunks? I want to loop through a Python list and process 2 list items at a time. Something like this in another language: for(int i = 0; i < list.length(); i+=2) { // do something with list[i] and list[i + 1] } What's the best way to accomplish t...

Help me refactor my World Cup Challenge Script

I am setting up a World Cup Challenge between some friends, and decided to practice my Ruby and write a small script to automate the process. The Problem: 32 World Cup qualifiers split into 4 tiers by their Fifa ranking 8 entries Each entry is assigned 1 random team per tier Winner takes all :-) I wrote something that suffices yet...