Subject: RE: [xsl] syntax for passing variable into XPath statement From: "Michael Kay" <mhk@xxxxxxxxx> Date: Fri, 6 Aug 2004 18:37:23 +0100 |
You haven't shown us the variable declaration, but I suspect it is not a number. Perhaps it is a result tree fragment. It would still look like a number when you print it. Perhaps you declared it as <xsl:variable name="n"><xsl:value-of select="3"/></xsl:variable> (I'm doing a Jeni here, trying to debug code you haven't shown me: but the above is a very common error.) Either declare it in a way that makes it a number, e.g. <xsl:variable name="n" select="3"/> or convert it to a number at the point where it is used in a numeric predicate /a/b/c/d[number($n)] The problem is that if you write a/b[$n] where $n isn't a number, it's converted to a boolean, not to a number. Converting a result tree fragment to a boolean always gives true, which means the predicate has no effect. Michael Kay > -----Original Message----- > From: Esther_Strom@xxxxxxxx [mailto:Esther_Strom@xxxxxxxx] > Sent: 06 August 2004 18:21 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] syntax for passing variable into XPath statement > > > > > > I'm pretty new at this, and haven't been able to find a > sample of what I'm > trying to do. I have a variable set up, and it is getting set > correctly - > I've got an fo:inline printing out the value of the variable > at each point > in the code. But I need to pass that variable into an XPath > statement as a > predicate (the variable is a number), and although it isn't > causing any > errors the way it is now, I don't think it's getting set. > Could someone > take a look and see if I'm doing something wrong? > > * I know the variable navNum is set correctly because of the value-of > statement inside the inline * > <xsl:apply-templates select="Zone2"/>z2 is at navNum<fo:inline > font-weight="bold"><xsl:value-of select="$navNum"/></fo:inline> > > * now I need to pass that variable number into here to get the correct > NavigationDivision element. If I hard-code a number in, the statement > provides the correct output * > <xsl:value-of > select="//MLPublication/NavigationDivision[$navNum]/Activity/T > itle[1]"/> > > I know in cases where you're passing a variable into a parameter you > enclose it in curly braces, but doing that causes my parser > to throw an > error. > |------------------------------| > | E S T H E R S T R O M, CLPP | > | Notes Application Development| > | McDougal Littell | > | 909 Davis Street | > | Evanston, IL 60201 USA | > | w: 847.424.3209 | > | e: esther_strom@xxxxxxxx | > |------------------------------|
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] syntax for passing variable i, Esther_Strom | Thread | RE: [xsl] syntax for passing variab, Esther_Strom |
[xsl] Manipulating Dates...serious , Gill, Fray | Date | RE: [xsl] How Use XSLT to Test For , Michael Kay |
Month |