You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Adam Jenkins <ad...@NTI.COM.AU> on 2008/03/17 22:47:44 UTC
setting a variable from within an extension element?
Hi All,
I need to be able to set a variable from within one of my extension elements for use in other parts of the scope. Is there any best practice way of doing this? I tried to emulate ElemVariable, but it was too complex. My element is quite simple, it creates a query string that later gets used in an extension function I have that emulates the document function. I think below will describe what I"m trying to achieve.
<param name="url"/>
<http:queryString var="myQueryString">
<param name="var" value="$somevar"/>
</http:queryString>
<xslvalue-of select="myFunc:htmlDocument(concat($url,$myQueryString))/html/head/title"/>
I have written custom functions and extensions before, so I'm no stranger there, I just need to know how to assign something to 'myQueryString' in the above example. I originally looked at using org.apache.xpath.VariableStack, but it assigns values based on indexes not names, so I'm a bit confused how that works.
Anyone have any suggestions?
Cheers
Adam
Number 1 in Truck Insurance
______________________________________________________________________
CAUTION - This message is intended for the addressee named above.
It may contain privileged or confidential information. If you are
not the intended recipient of this message you must not use,
copy, distribute or disclose it to anyone other than the addressee.
If you have received this email in error please return the message to the sender by replying to it and then delete the message from your computer.
Internet e-mails are not necessarily secure.
National Transport Insurance does not accept responsibility for changes made to this message after it was sent.
______________________________________________________________________
RE: xsl:template mode: #all, #default or mutiple modes supported?
Posted by "Winterflood, Jonathan" <jo...@capgemini.com>.
Well that explains, Thanks a lot!
However:
* I think Xalan should at least issue a warning when it encounters <xsl:stylesheet version="2.0"
* The error when using multiple modes suggests I can use a whitespace-separated list of modes, which is part of xslt2.0 ( """"An attribute whose value must be a QName or whitespace-separated list of QNames"""") [maybe this is because Xalan is moving towards 2.0]
OTOH, the program I edit the transformations in doesn't complain when I use these features while declaring <xsl:stylesheet version="1.0" ...
So it's back down to RTFM :-)
Thanks again,
Jonathan Winterflood
________________________________
De : keshlam@us.ibm.com [mailto:keshlam@us.ibm.com]
Envoyé : mardi 25 mars 2008 20:10
À : Winterflood, Jonathan
Cc : xalan-j-users@xml.apache.org
Objet : Re: xsl:template mode: #all, #default or mutiple modes supported?
Xalan is still a 1.0 processor. You're trying to use 2.0 features.
______________________________________
"... Three things see no end: A loop with exit code done wrong,
A semaphore untested, And the change that comes along. ..."
-- "Threes" Rev 1.1 - Duane Elms / Leslie Fish (http://www.ovff.org/pegasus/songs/threes-rev-11.html)
This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.
Re: xsl:template mode: #all, #default or mutiple modes supported?
Posted by ke...@us.ibm.com.
Xalan is still a 1.0 processor. You're trying to use 2.0 features.
______________________________________
"... Three things see no end: A loop with exit code done wrong,
A semaphore untested, And the change that comes along. ..."
-- "Threes" Rev 1.1 - Duane Elms / Leslie Fish
(http://www.ovff.org/pegasus/songs/threes-rev-11.html)
xsl:template mode: #all, #default or mutiple modes supported?
Posted by "Winterflood, Jonathan" <jo...@capgemini.com>.
Hi all,
I'm having difficulty getting an XSL to run on Xalan-j 2.7.0
Some template rules need to apply for all or multiple modes, but Xalan isn't accepting it.
Using #all or #default triggers a Transformer.transform()-time error """ Valeur incorrecte : #default utilisée pour l'attribut QNAME : mode """
Using a whitespace-separated list of modes triggers a TransformerFactory. newTransformer()-time exception with:
""" An attribute whose value must be a QName or whitespace-separated list of QNames had the value '(( insert my mode here ))'' """
I have written a minimal test to reproduce the problem:
(( java
Transformer trans = TransformerFactory.newInstance().newTransformer(
new StreamSource("trans.xslt") );
trans.transform(new StreamSource("simple.xml"),
new StreamResult(System.out));
))
(( xsl
<?xml version="1.0" encoding="iso-8859-15"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="text" version="1.0" encoding="iso-8859-15" indent="yes"/>
<xsl:template match="/">
foo
<xsl:apply-templates mode="aaaa"/>
</xsl:template>
<xsl:template match="test" mode="aaaa bbbb">bar</xsl:template>
</xsl:stylesheet>
))
Is this not supported, or am I missing something?
Citing http://www.w3.org/TR/xslt20/#modes :
A template rule is applicable to one or more modes. The modes to which it is applicable are defined by the mode attribute of the xsl:template element. If the attribute is omitted, then the template rule is applicable to the default mode. If the attribute is present, then its value must be a non-empty whitespace-separated list of tokens, each of which defines a mode to which the template rule is applicable. Each token must be one of the following:
* a QName, which is expanded as described in 5.1 Qualified Names to define the name of the mode
* the token #default, to indicate that the template rule is applicable to the default mode
* the token #all, to indicate that the template rule is applicable to all modes (that is, to the default mode and to every mode that is named in an xsl:apply-templates instruction or xsl:template declaration anywhere in the stylesheet).
TIA,
Jonathan Winterflood
This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.
Re: setting a variable from within an extension element?
Posted by Andy Chambers <ac...@googlemail.com>.
On Mon, Mar 17, 2008 at 10:14 PM, Adam Jenkins <ad...@nti.com.au> wrote:
> hmmmm, I like your second idea (too many parameters to make it a function -- would get messy)...so you're saying something like the following should work?
>
> <xsl:variable name="myvar">
> <http:queryString>
> <param name="1" value="1"/>
> <param name="2" value="2"/>
> </http:queryString>
> </xsl:variable>
>
> I wasn't aware you could put body text in xsl:variable, but if that works that's a great solution.
You can but when you do, the variable is a result tree fragment rather
than a nodelist. If you want to treat the result as a nodelist (e.g.
<xsl:for-each select="$myvar//a">...</xsl:for-each> to process all
anchors in your page), you'll need to use an extension function to
convert the result
into a node-list.
Sorry if this is obvious. It had me stumped for a while the first
time I came across it.
--
Andy
Re: setting a variable from within an extension element?
Posted by Adam Jenkins <ad...@NTI.COM.AU>.
hmmmm, I like your second idea (too many parameters to make it a function -- would get messy)...so you're saying something like the following should work?
<xsl:variable name="myvar">
<http:queryString>
<param name="1" value="1"/>
<param name="2" value="2"/>
</http:queryString>
</xsl:variable>
I wasn't aware you could put body text in xsl:variable, but if that works that's a great solution.
So to return data to the parent, do I just do
xslProcessorContext.outputToResultTree(...)
from within my extension element?
Number 1 in Truck Insurance
______________________________________________________________________
CAUTION - This message is intended for the addressee named above.
It may contain privileged or confidential information. If you are
not the intended recipient of this message you must not use,
copy, distribute or disclose it to anyone other than the addressee.
If you have received this email in error please return the message to the sender by replying to it and then delete the message from your computer.
Internet e-mails are not necessarily secure.
National Transport Insurance does not accept responsibility for changes made to this message after it was sent.
______________________________________________________________________
Re: setting a variable from within an extension element?
Posted by ke...@us.ibm.com.
The simplest solution is to write an extension function instead of an
extension element, and to call that from the xsl:variable's expression.
Next simplest is to have the extension element return the value and invoke
it within the body of an xsl:variable. Either of those approaches avoids
your having to get involved in the details of binding the value to a
variable.
______________________________________
"... Three things see no end: A loop with exit code done wrong,
A semaphore untested, And the change that comes along. ..."
-- "Threes" Rev 1.1 - Duane Elms / Leslie Fish
(http://www.ovff.org/pegasus/songs/threes-rev-11.html)