You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jacob Kjome <ho...@visi.com> on 2002/09/14 09:20:58 UTC

XSLT Filter question (slightly OT)

I have an XSLT filter working which filters *.xml files.  Each xml file has 
a stylesheet associated with it via an <?xml-stylesheet?> PI.  I extract 
the stylesheet like this...

TransformerFactory tf = TransformerFactory.newInstance();
SAXTransformerFactory stf = (SAXTransformerFactory)tFactory;
Source styleSource = stf.getAssociatedStylesheet(xmlSource, null, null, null);

This returns the Source object just fine.  However, it makes a difference 
how I reference the stylesheet....

1.  <?xml-stylesheet type="text/xsl" 
href="http://localhost:8080/mycontext/xml/mystylesheet.xsl"?>

This works fine as the Source knows exactly how to get the stylesheet on 
the web since it just gets it from the URL and I can do...

Transformer transformer = tf.newTransformer(xslSource);


2  1.  <?xml-stylesheet type="text/xsl" href="mystylesheet.xsl"?>

The source returned here thinks that this is a local file.  On windows, it 
uses File IO to look in C:\winnt\system32 to try to find the 
"mystylesheet.xsl" file rather than referencing the file where it actually 
exists in the current context that the filter is running in.


My question is, how can I make it so relatively referenced stylesheets get 
a reference to where they exist on the web?  That is, that they get pulled 
via a URL.  I understand that I'd have to provide the URL.  I just don't 
know how to go about setting the URL so that 
stf.getAssociatedStylesheet(xmlSource, null, null, null) returns a Source 
object which points to that source at the proper URL???

Am I going to have to do some sort of DOM manipulation and check whether a 
fully qualified URL has been set, set it if it hasn't, and then call 
stf.getAssociatedStylesheet(xmlSource, null, null, null)?  I'm hoping there 
is a simpler and more generic solution than that.

Any ideas?

Jake


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: XSLT Filter question (slightly OT)

Posted by Jacob Hookom <ho...@uwec.edu>.
Try using cocoon, or write your own filter that has a config file.  I
remember sending you some source code to go off of a while back.

-Jacob

| -----Original Message-----
| From: Jacob Kjome [mailto:hoju@visi.com]
| Sent: Saturday, September 14, 2002 1:43 PM
| To: Tomcat Users List
| Subject: Re: XSLT Filter question (slightly OT)
| 
| 
| Hi Peter,
| 
| Thanks for the response.
| 
| I take it you are talking about this:
| http://java.sun.com/webservices/docs/1.0/tutorial/doc/JSTL.html
| 
| The thing is, I am not using JSP in this case.  I am using a filter to
| generically transform documents of content type text/xml.  In this
| particular case, I am directly accessing XML documents such as
| http://localhost:8080/mycontext/xml/myxmldoc.xml.   myxmldoc.xml
contains
| PI specifying a stylesheet.  Tomcat's default servlet serves up the
xml
| document.  I am just filtering that response to transform it using the
| referenced xml stylesheet.  The way I get the stylesheet is through
the
| method stf.getAssociatedStylesheet(xmlSource, null, null, null) which
| returns a Source object.  I need to make sure that the Source object
| returned isn't retrieving the stylesheet via a File but via a URL.  I
can
| do this just fine if I've specified the URL, but I don't want to have
to
| do
| that.  I want to be able to refer to the stylesheet relative to the
| current
| position of the xml document.  I need to find a way to provide the
Source
| object with the URL information that I will only know for sure at
runtime,
| since the document could be served up in any number or different
| contexts.  I need a way to provide the base URL + context so that the
| Source gets the stylesheet via the URL.
| 
| Is there any way to do this which does not involve using JSP?  I
imagine
| there is.  I just need to find it.
| 
| Any other ideas?
| 
| Jake
| 
| What I need to do is make it transparent
| 
| At 07:32 AM 9/14/2002 -0700, you wrote:
| 
| >If you use JSTL and have the XSL stylesheets
| >accessible via a valid URL, it will automatically get
| >the servlet context and get the file using
| >requestdispatcher.include.
| >
| >peter
| >
| >--- Jacob Kjome <ho...@visi.com> wrote:
| > >
| > > I have an XSLT filter working which filters *.xml
| > > files.  Each xml file has
| > > a stylesheet associated with it via an
| > > <?xml-stylesheet?> PI.  I extract
| > > the stylesheet like this...
| > >
| > > TransformerFactory tf =
| > > TransformerFactory.newInstance();
| > > SAXTransformerFactory stf =
| > > (SAXTransformerFactory)tFactory;
| > > Source styleSource =
| > > stf.getAssociatedStylesheet(xmlSource, null, null,
| > > null);
| > >
| > > This returns the Source object just fine.  However,
| > > it makes a difference
| > > how I reference the stylesheet....
| > >
| > > 1.  <?xml-stylesheet type="text/xsl"
| > >
| >href="http://localhost:8080/mycontext/xml/mystylesheet.xsl"?>
| > >
| > > This works fine as the Source knows exactly how to
| > > get the stylesheet on
| > > the web since it just gets it from the URL and I can
| > > do...
| > >
| > > Transformer transformer =
| > > tf.newTransformer(xslSource);
| > >
| > >
| > > 2  1.  <?xml-stylesheet type="text/xsl"
| > > href="mystylesheet.xsl"?>
| > >
| > > The source returned here thinks that this is a local
| > > file.  On windows, it
| > > uses File IO to look in C:\winnt\system32 to try to
| > > find the
| > > "mystylesheet.xsl" file rather than referencing the
| > > file where it actually
| > > exists in the current context that the filter is
| > > running in.
| > >
| > >
| > > My question is, how can I make it so relatively
| > > referenced stylesheets get
| > > a reference to where they exist on the web?  That
| > > is, that they get pulled
| > > via a URL.  I understand that I'd have to provide
| > > the URL.  I just don't
| > > know how to go about setting the URL so that
| > > stf.getAssociatedStylesheet(xmlSource, null, null,
| > > null) returns a Source
| > > object which points to that source at the proper
| > > URL???
| > >
| > > Am I going to have to do some sort of DOM
| > > manipulation and check whether a
| > > fully qualified URL has been set, set it if it
| > > hasn't, and then call
| > > stf.getAssociatedStylesheet(xmlSource, null, null,
| > > null)?  I'm hoping there
| > > is a simpler and more generic solution than that.
| > >
| > > Any ideas?
| > >
| > > Jake
| > >
| > >
| > > --
| > > To unsubscribe, e-mail:
| > > <ma...@jakarta.apache.org>
| > > For additional commands, e-mail:
| > > <ma...@jakarta.apache.org>
| > >
| >
| >
| >__________________________________________________
| >Do you Yahoo!?
| >Yahoo! News - Today's headlines
| >http://news.yahoo.com
| >
| >--
| >To unsubscribe, e-mail:   <mailto:tomcat-user-
| unsubscribe@jakarta.apache.org>
| >For additional commands, e-mail: <mailto:tomcat-user-
| help@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: XSLT Filter question (slightly OT)

Posted by Jacob Kjome <ho...@visi.com>.
Hi Peter,

Thanks for the response.

I take it you are talking about this:
http://java.sun.com/webservices/docs/1.0/tutorial/doc/JSTL.html

The thing is, I am not using JSP in this case.  I am using a filter to 
generically transform documents of content type text/xml.  In this 
particular case, I am directly accessing XML documents such as 
http://localhost:8080/mycontext/xml/myxmldoc.xml.   myxmldoc.xml contains 
PI specifying a stylesheet.  Tomcat's default servlet serves up the xml 
document.  I am just filtering that response to transform it using the 
referenced xml stylesheet.  The way I get the stylesheet is through the 
method stf.getAssociatedStylesheet(xmlSource, null, null, null) which 
returns a Source object.  I need to make sure that the Source object 
returned isn't retrieving the stylesheet via a File but via a URL.  I can 
do this just fine if I've specified the URL, but I don't want to have to do 
that.  I want to be able to refer to the stylesheet relative to the current 
position of the xml document.  I need to find a way to provide the Source 
object with the URL information that I will only know for sure at runtime, 
since the document could be served up in any number or different 
contexts.  I need a way to provide the base URL + context so that the 
Source gets the stylesheet via the URL.

Is there any way to do this which does not involve using JSP?  I imagine 
there is.  I just need to find it.

Any other ideas?

Jake

What I need to do is make it transparent

At 07:32 AM 9/14/2002 -0700, you wrote:

>If you use JSTL and have the XSL stylesheets
>accessible via a valid URL, it will automatically get
>the servlet context and get the file using
>requestdispatcher.include.
>
>peter
>
>--- Jacob Kjome <ho...@visi.com> wrote:
> >
> > I have an XSLT filter working which filters *.xml
> > files.  Each xml file has
> > a stylesheet associated with it via an
> > <?xml-stylesheet?> PI.  I extract
> > the stylesheet like this...
> >
> > TransformerFactory tf =
> > TransformerFactory.newInstance();
> > SAXTransformerFactory stf =
> > (SAXTransformerFactory)tFactory;
> > Source styleSource =
> > stf.getAssociatedStylesheet(xmlSource, null, null,
> > null);
> >
> > This returns the Source object just fine.  However,
> > it makes a difference
> > how I reference the stylesheet....
> >
> > 1.  <?xml-stylesheet type="text/xsl"
> >
>href="http://localhost:8080/mycontext/xml/mystylesheet.xsl"?>
> >
> > This works fine as the Source knows exactly how to
> > get the stylesheet on
> > the web since it just gets it from the URL and I can
> > do...
> >
> > Transformer transformer =
> > tf.newTransformer(xslSource);
> >
> >
> > 2  1.  <?xml-stylesheet type="text/xsl"
> > href="mystylesheet.xsl"?>
> >
> > The source returned here thinks that this is a local
> > file.  On windows, it
> > uses File IO to look in C:\winnt\system32 to try to
> > find the
> > "mystylesheet.xsl" file rather than referencing the
> > file where it actually
> > exists in the current context that the filter is
> > running in.
> >
> >
> > My question is, how can I make it so relatively
> > referenced stylesheets get
> > a reference to where they exist on the web?  That
> > is, that they get pulled
> > via a URL.  I understand that I'd have to provide
> > the URL.  I just don't
> > know how to go about setting the URL so that
> > stf.getAssociatedStylesheet(xmlSource, null, null,
> > null) returns a Source
> > object which points to that source at the proper
> > URL???
> >
> > Am I going to have to do some sort of DOM
> > manipulation and check whether a
> > fully qualified URL has been set, set it if it
> > hasn't, and then call
> > stf.getAssociatedStylesheet(xmlSource, null, null,
> > null)?  I'm hoping there
> > is a simpler and more generic solution than that.
> >
> > Any ideas?
> >
> > Jake
> >
> >
> > --
> > To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> >
>
>
>__________________________________________________
>Do you Yahoo!?
>Yahoo! News - Today's headlines
>http://news.yahoo.com
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>

Re: XSLT Filter question (slightly OT)

Posted by Peter Lin <tc...@yahoo.com>.
If you use JSTL and have the XSL stylesheets
accessible via a valid URL, it will automatically get
the servlet context and get the file using
requestdispatcher.include.

peter

--- Jacob Kjome <ho...@visi.com> wrote:
> 
> I have an XSLT filter working which filters *.xml
> files.  Each xml file has 
> a stylesheet associated with it via an
> <?xml-stylesheet?> PI.  I extract 
> the stylesheet like this...
> 
> TransformerFactory tf =
> TransformerFactory.newInstance();
> SAXTransformerFactory stf =
> (SAXTransformerFactory)tFactory;
> Source styleSource =
> stf.getAssociatedStylesheet(xmlSource, null, null,
> null);
> 
> This returns the Source object just fine.  However,
> it makes a difference 
> how I reference the stylesheet....
> 
> 1.  <?xml-stylesheet type="text/xsl" 
>
href="http://localhost:8080/mycontext/xml/mystylesheet.xsl"?>
> 
> This works fine as the Source knows exactly how to
> get the stylesheet on 
> the web since it just gets it from the URL and I can
> do...
> 
> Transformer transformer =
> tf.newTransformer(xslSource);
> 
> 
> 2  1.  <?xml-stylesheet type="text/xsl"
> href="mystylesheet.xsl"?>
> 
> The source returned here thinks that this is a local
> file.  On windows, it 
> uses File IO to look in C:\winnt\system32 to try to
> find the 
> "mystylesheet.xsl" file rather than referencing the
> file where it actually 
> exists in the current context that the filter is
> running in.
> 
> 
> My question is, how can I make it so relatively
> referenced stylesheets get 
> a reference to where they exist on the web?  That
> is, that they get pulled 
> via a URL.  I understand that I'd have to provide
> the URL.  I just don't 
> know how to go about setting the URL so that 
> stf.getAssociatedStylesheet(xmlSource, null, null,
> null) returns a Source 
> object which points to that source at the proper
> URL???
> 
> Am I going to have to do some sort of DOM
> manipulation and check whether a 
> fully qualified URL has been set, set it if it
> hasn't, and then call 
> stf.getAssociatedStylesheet(xmlSource, null, null,
> null)?  I'm hoping there 
> is a simpler and more generic solution than that.
> 
> Any ideas?
> 
> Jake
> 
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


__________________________________________________
Do you Yahoo!?
Yahoo! News - Today's headlines
http://news.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: XSLT Filter question (slightly OT)

Posted by Peter Lin <tc...@yahoo.com>.
If you use JSTL and have the XSL stylesheets
accessible via a valid URL, it will automatically get
the servlet context and get the file using
requestdispatcher.include.

peter

--- Jacob Kjome <ho...@visi.com> wrote:
> 
> I have an XSLT filter working which filters *.xml
> files.  Each xml file has 
> a stylesheet associated with it via an
> <?xml-stylesheet?> PI.  I extract 
> the stylesheet like this...
> 
> TransformerFactory tf =
> TransformerFactory.newInstance();
> SAXTransformerFactory stf =
> (SAXTransformerFactory)tFactory;
> Source styleSource =
> stf.getAssociatedStylesheet(xmlSource, null, null,
> null);
> 
> This returns the Source object just fine.  However,
> it makes a difference 
> how I reference the stylesheet....
> 
> 1.  <?xml-stylesheet type="text/xsl" 
>
href="http://localhost:8080/mycontext/xml/mystylesheet.xsl"?>
> 
> This works fine as the Source knows exactly how to
> get the stylesheet on 
> the web since it just gets it from the URL and I can
> do...
> 
> Transformer transformer =
> tf.newTransformer(xslSource);
> 
> 
> 2  1.  <?xml-stylesheet type="text/xsl"
> href="mystylesheet.xsl"?>
> 
> The source returned here thinks that this is a local
> file.  On windows, it 
> uses File IO to look in C:\winnt\system32 to try to
> find the 
> "mystylesheet.xsl" file rather than referencing the
> file where it actually 
> exists in the current context that the filter is
> running in.
> 
> 
> My question is, how can I make it so relatively
> referenced stylesheets get 
> a reference to where they exist on the web?  That
> is, that they get pulled 
> via a URL.  I understand that I'd have to provide
> the URL.  I just don't 
> know how to go about setting the URL so that 
> stf.getAssociatedStylesheet(xmlSource, null, null,
> null) returns a Source 
> object which points to that source at the proper
> URL???
> 
> Am I going to have to do some sort of DOM
> manipulation and check whether a 
> fully qualified URL has been set, set it if it
> hasn't, and then call 
> stf.getAssociatedStylesheet(xmlSource, null, null,
> null)?  I'm hoping there 
> is a simpler and more generic solution than that.
> 
> Any ideas?
> 
> Jake
> 
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


__________________________________________________
Do you Yahoo!?
Yahoo! News - Today's headlines
http://news.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>