Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Re: Specify an element in a nodeset directly >Thread Next - Re: Specify an element in a nodeset directly Re: Specify an element in a nodeset directlyTo: NULL Date: 10/3/2006 1:29:00 PM eric.goforth@g... wrote: > Martin Honnen wrote: > > eric.goforth@g... wrote: > > > <xsl:value-of select=" > > > $myblahs/blah[/xpath1/xpath2/someintegervalue]/yada > > > "/> > > > > $myblahs/blah > > [/xpath1/xpath2/someintegervalue=position()]/yada > > Hmmm, that's not working for me. If I put in a "1" or a > "2" it works, but not with the "variable". Your example is awfully vague. For better results, provide a sample XML and a minimum XSLT demonstrating your problem. > <xsl:template match="thing[(position() mod 2)=1]"> > <xsl:param name="furballs"/> > <!-- This works--> > <xsl:value-of select="thingintegerfield1"/> > <!-- This does not work--> > <xsl:value-of select=" > $furballs/furball[1=thingintegerfield1]/furballmember > "/> > </xsl:template> First of all, the [1=thingintegerfield1] predicate should be [position()=thingintegerfield1] if I understood correctly what you're trying to do (it's hard to be sure without a working example). Even then, I'd say you don't understand how contexts work. Let's assume this template matched the node /foo[1]/bar[1]/thing[1]. What does thingintegerfield1 in the XPath marked as 'This works' refer to then? The answer is '/foo[1]/bar[1]/thing[1]/thingintegerfield1'. And what does thingintegerfield1 in the XPath marked as 'This does not work' refer to? '$furballs/furball/thingintegerfield1'. What you probably need is current()/thingintegerfield1, although, once again, it's hard to be sure without a working example. To demonstrate: XML: <?xml version="1.0" encoding="UTF-8"?> <foo> <bar> <xyzzy> <int>3</int> </xyzzy> </bar> <nodeset> <node> <str>wrong (1)</str> <int>3</int> </node> <node> <str>wrong (2)</str> <int>2</int> </node> <node> <str>right (3)</str> <int>1</int> </node> </nodeset> </foo> XSLT: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:apply-templates select="descendant::xyzzy"> <xsl:with-param name="ns" select="/foo/nodeset"/> </xsl:apply-templates> </xsl:template> <xsl:template match="/foo/bar/xyzzy"> <xsl:param name="ns"/> My Int: <xsl:value-of select="int"/> Wrong: <xsl:value-of select=" $ns/node[int=position()]/str"/> Right: <xsl:value-of select=" $ns/node[current()/int=position()]/str"/> </xsl:template> </xsl:stylesheet> -- roy axenov | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
