Subject: Re: [xsl] Passing variables into XSLT via parameters ... can't get it to work From: Duncan Anker <danker@xxxxxxxxxxxxx> Date: Wed, 24 May 2006 11:10:19 +1000 |
<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.
value-of produces the string value of whatever is selected, so there you
are selecting a node set but coercing it to a string by taking all its
character data and losing the element structure.
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 probably want xsl:copy-of
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
is defined, which you don't show. Since it's not defined in this
template it must be a global parameter or variable in which case
it may well already be a node set.
<parameters> <namespace1 variable1="foo" variable2="bar" /> <namespace2 variable1= ... /> </parameters>
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.
[As an aside, I couldn't get the substring-before and -after to work directly in the XPath expression. Am I missing something, or do they need to be assigned to variables like that to be used?]
You can always replace a variable by its value in XPath, no expression
requires variables.
> 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.
by escape do you mean < etc? value-of does not do any escaping in
that sense. If value-of is producing that then $parameters does not
contain an XML tree but rather a string containing XML markup in which
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.
provide extension functions giving access to an XML parser or you could
parse it outside xslt and pass in the parsed document node as a
parameter. (I don't know the details of php/libxslt here)
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Passing variables into XS, David Carlisle | Thread | Re: [xsl] Passing variables into XS, David Carlisle |
RE: [xsl] Absolute/relative positio, Hood, Earl | Date | Re: [xsl] Passing variables into XS, David Carlisle |
Month |