XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 28th, 2004, 02:43 PM
mountainbiker mountainbiker is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 27 mountainbiker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 56 m
Reputation Power: 0
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.

Reply With Quote
  #2  
Old January 28th, 2004, 02:54 PM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
You need an <xsl:param> element in your xsl file. Here's a quick primer: http://www.w3schools.com/xsl/el_param.asp

Reply With Quote
  #3  
Old January 28th, 2004, 03:12 PM
MattSidesinger's Avatar
MattSidesinger MattSidesinger is offline
Java PHP Oracle Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: C-Bus OH-IO
Posts: 204 MattSidesinger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 26 sec
Reputation Power: 5
Send a message via AIM to MattSidesinger
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.

Reply With Quote
  #4  
Old January 28th, 2004, 04:29 PM
mountainbiker mountainbiker is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 27 mountainbiker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 56 m
Reputation Power: 0
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.

Reply With Quote
  #5  
Old January 29th, 2004, 02:30 AM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
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.

Reply With Quote
  #6  
Old January 29th, 2004, 05:14 AM
mountainbiker mountainbiker is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 27 mountainbiker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 56 m
Reputation Power: 0
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.

Reply With Quote
  #7  
Old January 29th, 2004, 03:01 PM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
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.

Reply With Quote
  #8  
Old January 30th, 2004, 02:13 AM
mountainbiker mountainbiker is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 27 mountainbiker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 56 m
Reputation Power: 0
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.

Reply With Quote
  #9  
Old January 30th, 2004, 03:06 AM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
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.

Reply With Quote
  #10  
Old January 30th, 2004, 05:09 PM
mountainbiker mountainbiker is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 27 mountainbiker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 56 m
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > How do you use the -param option of Xalan-J


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT