[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: xsl:for-each with atomic values and nested xsl:ap
Hi, Christian, By using tokenize inside a for-each, you've set the context to a string that has no relationship to your input document. To fix it, use a variable that contains the root element (I call those "anchor variables"), thus: <xsl:template match="src"> <xsl:variable name="root" select="/" <xsl:for-each select="tokenize( 'a c', '[ ]')"> <xsl:apply-templates select="$root/doc/*[current() eq string(@id)]" /> </xsl:for-each> </xsl:template> That way, your apply-templates instruction finds the context you need. Jay Bryant Bryant Communication Services ----- Original Message ----- From: "Christian Roth" <roth@xxxxxxxxxxxxxx> To: "XSL List" <XSL-List@xxxxxxxxxxxxxxxxxxxxxx> Sent: Wednesday, September 13, 2006 5:12 PM Subject: xsl:for-each with atomic values and nested xsl:apply-templates > Hi, > > trying to figure out what the error with this fragment (XSLT 2) is: > > > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > version="2.0"> > > <xsl:template match="src"> > <xsl:for-each select="tokenize( 'a c', '[ ]')"> > <xsl:apply-templates select="/doc/*[current() eq string(@id)]" /> > </xsl:for-each> > </xsl:template> > > </xsl:stylesheet> > > > This gives an error, "Cannot select a node here: the context item is an > atomic value". > > I see that the xsl:for-each iterates over a sequence of atomic values > (xs:string). So I assume that current() results in an xs:string, which > should be comparable to the string(@id) expression. The select="..." > expression does not depend on a context node, as it is an absolute path > from the document root. xsl:apply-templates results in a sequence and > therefore should be no problem in the xsl:for-each body. It's certainly > trivial - I just don't see it right now... :-/ > > An input for the above would e.g. be: > > > <doc> > <src /> > <elem id="a">A</elem> > <elem id="b">B</elem> > <elem id="c">C</elem> > <elem id="d">D</elem> > </doc> > > > The desired output would (probably...) be: > > AC > > > Regards, Christian
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|