You should iterate first over the 'time' elements to filter them according your needs. After that you can iterate over the 'temperature' sub-elements. Something like this:
import lxml.etree as etree
with open('Stockholm.xml', 'rt') as wreport:
xml = etree.parse(wreport)
for record in xml.iter('time'):
if record.attrib['period'] == '2':
for temp in record.iter('temperature'):
print 'In Stockholm it will today be %s celcius from %s to %s\n' %
(temp.attrib['value'],
record.attrib['from'],
record.attrib['to'])
Alternatively, you can use XPath like filtering:
import lxml.etree as etree
with open('Stockholm.xml', 'rt') as wreport:
xml = etree.parse(wreport)
for temp in xml.findall('.//time[@period="2"]/temperature'):
print 'In Stockholm it will today be %s celcius\n' %
temp.attrib['value']