Re: Passing variables into XSLT via parameters ... can
David Carlisle wrote:
<xsl:value-of select="exslt:node-set($parameters)//*[name() = ....For the purposes of what I am currently trying to do, there should only ever be one element in the node set.
Perhaps. I was anticipating replacing certain elements with string values so value-of seemed okay, although in the event of needing to pass HTML in maybe I will need to switch, I will keep it in mind.
You may or may not need exslt:node-set() it depends on how $parameters$parameters is defined as a string passed in from the processor, and my understanding was that I needed to coerce to a node set explicitly; it would be something like
<parameters> <namespace1 variable1="foo" variable2="bar" /> <namespace2 variable1= ... /> </parameters>
This may not be the ideal way to do it; What I was hoping to achieve was a way to pass in arbitrary variables without having to hardcode variable names into the stylesheet and preferably avoiding having to make 2 passes - initial experimentation had the HTML fragments as stylesheets to format the dynamic content and then the result passed into a layout stylesheet. Storing the HTML as content and being able to use aditional XML seems a bit cleaner.
I may actually have to rethink the whole thing again, since it occurred to me that I won't be able to use variables in attributes via this method, but for now that's what I have. I did another test and it seems that when I define $parameters in the stylesheet it is a node set and when I pass it in it is a string - I am not surprised that it is a string, that is whay I am using exslt:node-set in the first place, however maybe it is not coercing correctly. The difference between the node set and the string would probably be the root cause of my problem, although I thought I was working with a node-set because of the explicit call there.
That's what I thought, so was confused when it didn't happen. The thing I was missing, as pointed out by Kasimier Buchcik, is the use of the current() function because the context node changes in a predicate.
> I know the string is making it in becauseThat was what I meant. I was using value-of to confirm that $parameters had a value when it was being passed in. As mentioned above, it does appear that my problem is a node set vs a string depending on internal or external use.<xsl:value-of select="$parameters" /> prints out the escaped string.
case you need to parse it with an XML parser first. Some processorsI haven't seen any way to pass a parsed document node into libxslt, I don't believe it can be done. It's possible to call PHP functions from the stylesheet but I would rather keep them language-agnostic where possible, which means doing it in xslt. I had thought that exslt:node-set *was* the external XML parser but evidently not. I'll look into that.
Thanks for your help.
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