try "item" instead of "/item"
sorry, that was a really hasty reply. I haven't actually tested your sample, or my suggestion, in an XSLT debugger.
I'm guessing the problem is just the XPATH in your for-each. While you're inside the "info" template, you're in the "info" scope. So your XPATH, relative to "info", is "item", since item is a direct child of info. It's a lot like defining relative paths or URLs; you can define an XPATH relative to the context of the current node of template you're in.
"item" matches an item as the child of whatever the current node is. "/item" tells XPATH to look for an item at the root node. "//item" would match an item anywhere in the tree.
I hope that makes enough sense. If you can't crack this one quickly, reply back.
Thanks, httpwebwitch, but no luck. Nothing seems be be filtering through.
Thanks for your second response, httpwebwitch (only just saw it). Still not able to crack this.
Had to specify the corresponding namespace in the XML and use it as a prefix on each parameter for this to work.
I have a related question. How do I substitute spaces in the XML with underscores?
e.g. XML file contains "The cumulus cloud"
but I need it to return as "The_cumulus_cloud"
This is what I've tried:
<xsl:variable name="cname"><xsl:value-of select="ab:name"/></xsl:variable>
<xsl:attribute name="src"><xsl:value-of select="translate($cname,'','_')"/>.jpg</xsl:attribute>
The translate() function is the most efficient for simple character substitution.
There are also old-fashioned string replace templates [xml.com] you can try, if you're limited to using XSLT 1.0
in your example there isn't a space in the second parameter
that could be the problem
Well spotted & thank you, that was it. Thanks for sharing the link.
httpwebwitch, I have one more question.. I also had a look at the "Splitting and transforming strings" article on xml.com, but can't get this one figured out.
If I have comma separated values in the XML, how can I split these into divs?
What I'd like to output is
<div class="type" id="1">cumulus</div>
<div class="type" id="2">stratus</div>
<div class="type" id="3">nimbus</div>
The solution probably requires making use of a template, but what has thrown me off is the fact that there are only two commas, so I can't use
<xsl:value-of select="substring-before(., ':')"/> or
<xsl:value-of select="substring-after(., ':')"/>
Thanks for your help.
yeah... it's like you need a split() function for that. I wonder if one already exists out there in opensourceland?
That's one of the things that bothers me about XSLT - all the basic functions you expect to be available are missing. Things like replace() and split() and join() and stuff like that. It feels like trying to eat with only one chopstick.
But that's because I'm approaching XSLT being already familiar with OOP programming and scripting. It's actually a brilliant language... and XSLT2.0 is much better and fully-featured.
Unfortunately, PHP (my language of choice) doesn't have an XSLT2.0 parser
That last question is a neat XSLT challenge, and there are some lurkers here who enjoy a good XSLT challenge. Would you mind pasting it into a new thread?
Thanks for your response and helpful comments. I have created a new thread for the last question I had.