[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: syntax for passing variable into XPath statement

Subject: RE: syntax for passing variable into XPath statement
From: Esther_Strom@xxxxxxxx
Date: Mon, 9 Aug 2004 09:56:34 -0500
xsl variable in xpath
I'm on the digest version, so just got your response now, Michael. This is
my variable declaration:

 <xsl:variable name="navNum"><xsl:number level="single"
count="//NavigationDivision"/></xsl:variable>

I had assumed that since the variable was set by using the xsl:number
element that the variable value was a number - apparently not. I used your
second suggestion (converting it at the point where it's used) and that
worked.

Thanks,

Esther

>
> Date: Fri, 6 Aug 2004 18:37:23 +0100
> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> From: "Michael Kay" <mhk@xxxxxxxxx>
> Subject: RE:  syntax for passing variable into XPath statement
>
> 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:  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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.