Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 9th, 2007, 05:46 AM
Authorized User
 
Join Date: Nov 2007
Posts: 33
Thanks: 2
Thanked 0 Times in 0 Posts
Default import file from jar

Hi,

Does anyone know how to import file from the jar?

I packed my application as an executable jar.
Here's my jar structure:
Test.jar
   -> META-INF
   -> config
        -> myXSL.xslt
        -> config.xml
   -> classes
        -> a.class
        -> etc

I need to read 'config.xml' from 'myXSL.xslt'.
Something like
<xsl:variable name="data" select="document('config.xml')" />

Thanks,


 
Old November 9th, 2007, 05:51 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I think it depends greatly on which XSLT processor you are using. I think I've seen that some provide a jar reading format for the url that document(). (e.g. jar:file:///foo/bar.jar!/com/sample/baz.xsl) How you determine the current jar file I'm not sure.

http://www.dpawson.co.uk/xsl/sect2/N4760.html#d6519e349


/- Sam Judson : Wrox Technical Editor -/
 
Old November 9th, 2007, 06:03 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

This kind of thing tends to be processor-dependent - you need to ask the question of a specific processor, it's not an XSLT language issue. Some processors may support relative URI addressing within a JAR file, others may not. (With Saxon, it depends which version you are using). In all cases, relative URI addressing will only work if the base URI is known, and that depends on how you identify the styesheet to the XSLT processor.

The jar: URL scheme is not particularly well documented - I think the best description I found was in the JDK Javadoc documentation for class java.net.JarURLConnection. A complication is that the syntax of jar: URLs isn't actually compatible with the RFCs for URIs, and isn't in fact supported by Sun's own java.net.URI class. This technically means that an XSLT processor that supports these URLs is non-conformant...

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 9th, 2007, 06:19 AM
Authorized User
 
Join Date: Nov 2007
Posts: 33
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Thanks a lot :D It works.

Because I'm parsing a parameter for the path, therefore I have the java determine where the jar located.

But it'll be good to know how to determine the current jar location in XSLT :) I'll post the answer when I found out how.







Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading xml file which is in a JAR file pradheepayyanar J2EE 2 December 26th, 2007 05:52 AM
cant use jar file SweeT EviL Java Basics 1 October 9th, 2007 11:48 AM
JAR File Obfuscate Anandharaj Struts 0 September 26th, 2007 07:43 AM
JAR file sugarpalm157 Pro Java 1 August 23rd, 2007 08:27 AM
Accessing properties file outside jar file anand_indya J2EE 0 December 8th, 2004 06:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.