|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
How do you use the -param option of Xalan-J
I cannot seem to get the -param command-line option of xalan to work.
command-line Code:
java org.apache.xalan.xslt.Process
-in a.xml -xsl a.xsl -out a.html -param a 1
xml Code:
<?xml version="1.0" encoding="UTF-8"?> <A></A> xsl Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<h1>[<xsl:value-of select="$a"/>]</h1>
</xsl:template>
</xsl:stylesheet>
error Code:
could not find the variable with name of a Last edited by mountainbiker : January 28th, 2004 at 05:06 PM. |
|
#2
|
|||
|
|||
|
You need an <xsl:param> element in your xsl file. Here's a quick primer: http://www.w3schools.com/xsl/el_param.asp
|
|
#3
|
||||
|
||||
|
More info, please / solution?
bricker42: Could you provide an example where this xsl:param would go in the document? I am new to calling xalan from the command line and would like to know how to pass parameters in the future for my own knowledge.
If bricker42's post does not help, does this help? -param a "'1'" Last edited by MattSidesinger : January 28th, 2004 at 03:18 PM. |
|
#4
|
|||
|
|||
|
Matt: I read other stuff on the web about doing it as a string like "''", but this unfortunately also doesn't work (for me).
bricker42: I tried something like Code:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:param name="a" select="'some-default-value'"/> <xsl:template match="/"> <h1>[<xsl:value-of select="$a"/>]</h1> </xsl:template> </xsl:stylesheet> AND <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:param name="a"/> <xsl:template match="/"> <h1>[<xsl:value-of select="$a"/>]</h1> </xsl:template> </xsl:stylesheet> However, this added xsl:param overrode any attempt at passing the param from the command-line. Additionally, moving xsl:param into the template still had the same affect (but local vice global). Last edited by mountainbiker : January 29th, 2004 at 05:03 AM. |
|
#5
|
|||
|
|||
|
Well, you've confused me a bit
. You posted the same snippet of xsl twice. What you posted is the correct way to use <xsl: param>, though. The only thing I would add is to set a default value for the parameter so that the code still works even if you don't pass a parameter.What output do you get when you run java org.apache.xalan.xslt.Process -in a.xml -xsl a.xsl -out a.html -param a 1 ? I would expect the output to be "<h1>1</h1>". Is that not what you're getting? Last edited by bricker42 : January 29th, 2004 at 02:33 AM. |
|
#6
|
|||
|
|||
|
The first snippet was suppose to show the default value if nothing supplied, and the second was without the optional value.
In both cases, at the commad-line we call xalan with -param a "'1'" as well as the other variants. However, the output I get is [some-default-value] or [] Thus, the use of the <xsl: param> in this way appears to override any hopes of seeing it defined from the command-line. The apache and other documentation appear to show it as I have shown; however, the documentation is lacking in how to implement/retrieve it from the xslt stylesheet. The other command-line options that I use work without problem, so it must (hopefully) be something small we're missing. Last edited by mountainbiker : January 29th, 2004 at 05:18 AM. |
|
#7
|
|||
|
|||
|
Well, I finally setup xalan so I could test this and I'm not sure why you're having a problem :). Here's what I did.
xml file: Code:
<?xml version="1.0"?> <doc>Hello</doc> xsl file (the same one you posted): Code:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:param name="a" select="'some-default-value'"/> <xsl:template match="/"> <h1>[<xsl:value-of select="$a"/>]</h1> </xsl:template> </xsl:stylesheet> batch file: Code:
set XALAN_HOME=C:\java_lib\xalan-j_2_5_2\bin set CLASSPATH=%XALAN_HOME%\bsf.jar set CLASSPATH=%CLASSPATH%;%XALAN_HOME%\xalan.jar set CLASSPATH=%CLASSPATH%;%XALAN_HOME%\xalansamples.jar set CLASSPATH=%CLASSPATH%;%XALAN_HOME%\xercesImpl.jar set CLASSPATH=%CLASSPATH%;%XALAN_HOME%\xml-apis.jar set CLASSPATH=%CLASSPATH%;%XALAN_HOME%\xsltcapplet.jar set CLASSPATH=%CLASSPATH%;%XALAN_HOME%\xsltcbrazil.jar set CLASSPATH=%CLASSPATH%;%XALAN_HOME%\xsltcejb.jar set CLASSPATH=%CLASSPATH%;%XALAN_HOME%\xsltcservlet.jar %JAVA_HOME%\bin\java org.apache.xalan.xslt.Process -in test.xml -xsl test.xsl -out test.html -param a 1 output: Code:
<?xml version="1.0" encoding="UTF-8"?> <h1 xmlns:fo="http://www.w3.org/1999/XSL/Format">[1]</h1> Can you try running something similar and see what results you get? This is using JDK 1.4.1_01. |
|
#8
|
|||
|
|||
|
I am using SDK 1.4.2_02 and _03. The EXSLT extensions aren't in the Xalan in the SDK, so an Apache recommendation is to add the select Xalan jar files to %JAVA_HOME%\lib\endorsed. With this said, I have tried to run a modified version of your batch file:
Code:
set XALAN_HOME=C:\program files\xalan\bin set CLASSPATH=%XALAN_HOME%\bsf.jar set CLASSPATH=%CLASSPATH%;%XALAN_HOME%\xalan.jar set CLASSPATH=%CLASSPATH%;%XALAN_HOME%\xalansamples.jar set CLASSPATH=%CLASSPATH%;%XALAN_HOME%\xercesImpl.jar set CLASSPATH=%CLASSPATH%;%XALAN_HOME%\xml-apis.jar set CLASSPATH=%CLASSPATH%;%XALAN_HOME%\xsltcapplet.jar set CLASSPATH=%CLASSPATH%;%XALAN_HOME%\xsltcbrazil.jar set CLASSPATH=%CLASSPATH%;%XALAN_HOME%\xsltcejb.jar set CLASSPATH=%CLASSPATH%;%XALAN_HOME%\xsltcservlet.jar rem *** TEST WITH EXSLT rem *** %JAVA_HOME%\bin\java -Djava.endorsed.dirs="%JAVA_HOME%\lib\endorsed" -cp "%JAVA_HOME%\lib\endorsed\xalan.jar;%JAVA_HOME%\lib\endorsed\xercesImpl.jar" org.apache.xalan.xslt.Process -in %1 -xsl %2 -out %3 -param %4 %5 rem *** RENAME ENDORSED DIRECTORY AND RUN WITHOUT EXSLT %JAVA_HOME%\bin\java org.apache.xalan.xslt.Process -in %1 -xsl %2 -out %3 -param %4 %5 In short, I am running Xalan 2.5, and I have tried to run Xalan with and without the extensions--but to no success. However, it is encouraging that you got it to work which would leave me to believe I have some goofy setup/comflict in my setup here and at work. We do have Xalan on another box with our Documentum folks which is maybe setup differently. I will have to make enquiries and have them test it when they can. Until then I will have to keep plugging away at this one give the info you have provided. |
|
#9
|
|||
|
|||
|
Just for giggles can you try writing a java class to do the transform? Just to see if it's related to the command line usage.
Also, try running the param sample that comes with Xalan. If you can get the sample to work that'll give you a starting point. |
|
#10
|
|||
|
|||
|
I have reloaded my java environment and viola. It is now working as documented, but I cannot break it to see where the problem was located. My work install is like my previous not working home install, so I will have to play with it there. Although if I cannot get it going quickly, I'll do the same thing as I don't thing work will want me devoting too much time to this aspect of the project. Thanks for all the help.
Last edited by mountainbiker : February 1st, 2004 at 09:18 AM. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > How do you use the -param option of Xalan-J |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|