This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Using parameter in for-each select - newbie question


Hi Chris,

>       <xsl:for-each select="//$table">
>          <xsl:call-template name="create-csv"/>
>       </xsl:for-each>

Variables aren't text macros - you can't use a variable reference to
insert some text into an XPath.  Basically, this is illegal XPath
expression syntax, which is why you're getting the error.

You're aiming here for a dynamic XPath to pick the elements that you
want.  Rather than trying to construct the XPath dynamically, you can
pick all the elements and filter them (using a predicate) to choose
only those whose name is the same as the value of the $table
parameter, i.e.:

  //*[local-name() = $table]

If you start having $table hold more sophisticated XPaths than just
the name of an element, then you may have to use an extension function
that gives dynamic evaluation of strings as XPaths, such as
saxon:evaluate():

  saxon:evaluate(concat('//', $table))

I don't know of an equivalent extension function in xt, I'm afraid.

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]