OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: XSLT and Java



Questions regarding XSLT, in general, are best dealt with at the XSL
list: xsl-list@lists.mulberrytech.com. There you will usually get a
complete and correct answer, promptly.

Some pointers:
To pass a parameter to a stylesheet, declare a top level xsl:param. 
Your java code can then set the value of that param using the
Transformer.setParameter() method before transformation. 

This approach is much cleaner that modifying the stylesheet each time.
If there are a *lot* of "issues", then you might consider extracting the
relevent "issue" before transformation, and passing that single "issue"
to the stylesheet. That approach might be faster as you are only
interested in one "issue". 

I don't know why you are getting the error when constructing a
Transformer from a DOM source.

> -----Original Message-----
> From:	Joel Beach [SMTP:joelbeach@optushome.com.au]
> Sent:	Friday, July 06, 2001 2:38 PM
> To:	xml-dev@lists.xml.org
> Subject:	XSLT and Java
> 
> Hi Everyone,
> 
> Not sure whether this is offtopic or not.
> 
> Just wondering if anyone has some suggestions on my problem. I have an
> XML
> file with a basic structure which looks something like the following.
> 
> <Issues>
>                 <Issue ID="1">
>                     <IssueName>Lentil-killing parasites</IssueName>
>                     <IssueDescription>
>                         <Paragraph>At the moment Lentil-killing
> parasites
>                             are ravaging the Trial. This could affect
> all
>                             people growing Lentils. As a precaution,
>                             we recommend that all farmers stop reading
> too
>                             much science fiction. This goes for
> students
>                             defining the XML formats for 340 projects
>                             as well.
>                         </Paragraph>
>                     </IssueDescription>
>                     <MultimediaItems>
>                         <MMObject ID="5">
>                             <Image>
>                                 <MMLocation>Image.jpg</MMLocation>
>                                 <MMName>Picture of plot</MMName>
>                                 <ImageWidth>640</ImageWidth>
>                                 <ImageHeight>480</ImageHeight>
>                                 <FileSize>80</FileSize>
>                             </Image>
>                         </MMObject>
>                     </MultimediaItems>
>                 </Issue>
>  </Issues>
> 
> Each Issue has a unique ID, and I want to be able to apply an XSL
> stylesheet
> in Java (using JAXP) so that I apply to only one Issue.
> 
> Basically, I was wondering if there was a way to write a stylesheet
> such
> that a parameter can be passed to it and a transform performed with
> the
> stylesheet after the parameter is substituted. My current idea is to
> naively
> generate the stylesheet by printing out to a temp file, and then using
> the
> temp file as my stylesheet. This is most likely to be slow. Is there a
> better way?
> 
> At first I thought about parsing the XSL stylesheet through the DOM,
> altering the appropriate node and then using the altered Document as a
> DOMSource for the XSLT transformer. However, using JAXP 1.1, I can't
> instantiate a Transformer using a DOMSource as an argument to the
> constructor. It always complains that stylesheet requires a version
> attribute. This attribute is present in the file (<xsl:stylesheet
> version="1.0" ...>).
> 
> Any ideas....is there some compatability problem. If I use a SAXSource
> or a
> StreamSource to make the Transformer, everything works out fine....why
> is
> DOMSource different?
> 
> Joel
> 
> 
> ------------------------------------------------------------------
> The xml-dev list is sponsored by XML.org, an initiative of OASIS
> <http://www.oasis-open.org>
> 
> The list archives are at http://lists.xml.org/archives/xml-dev/
> 
> To unsubscribe from this elist send a message with the single word
> "unsubscribe" in the body to: xml-dev-request@lists.xml.org