xsl-list
[Top] [All Lists]

Passing params to XSLT from Java - Exception

2002-12-04 05:06:01
Hello,

I am trying to pass params to a xsl stylesheet from a Java application.  It 
falls over with the following error

"org.xml.sax.SAXParseException: Content is not allowed in prolog." and it 
seems as if this is caused by the parameters. I have included both the xslt 
and java code snippet.  Any suggestions are most welcome.

Thanks
Julie.

<?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:output method="html" indent="yes" omit-xml-declaration="no" 
version="1.0"/> 
        <xsl:param name="highPref"/>
        <xsl:param name="medPref"/>
        <xsl:param name="lowPref"/>     

        <xsl:template match="/">
                <html>
                        <head>
                                <title></title>
                        </head>
                        <body>
                                <xsl:variable name="cats" 
select="InfoStreamResults/Article/Categories/Category[.=$highPref 
or .=$medPref or .=$lowPref]"/>
                                <xsl:variable name="articles">
                                        <xsl:for-each select="$cats">
                                                <xsl:value-of 
select="./../.."/>
                                        </xsl:for-each>                 
        
                                </xsl:variable>

                                <xsl:variable name="art" select="$cats/../.."/>
                                <xsl:for-each select="$art[(_at_)ID != 
preceding::Article/@ID]">
                                        <xsl:variable name="relativeUrl">
                                                <xsl:value-of 
select="'newsStory.xml?'"/>
                                        </xsl:variable>
                                
                                        <xsl:variable name="heading">
                                                <xsl:value-of 
select="Heading"/>                      
                                        </xsl:variable>
                                        
                                        <xsl:variable name="articleId">
                                                <xsl:value-of select="concat
('articleId=',@ID)"/>
                                        </xsl:variable>
                                        
                                        <xsl:variable name="categoryId">
                                                <xsl:for-each 
select="Categories/Category">
                                                        <xsl:value-of 
select="concat('&amp;categoryId', position(), '=', @ID)"/>
                                                </xsl:for-each>
                                        </xsl:variable>                 
                                        
                                        <a href="{$relativeUrl}{$articleId}
{$categoryId}">
                                                <xsl:value-of 
select="$heading"/>
                                        </a>
                                        <br />
                
                                </xsl:for-each>
                        </body>
                </html>
        </xsl:template>

</xsl:stylesheet>


Writer transformedXml = new StringWriter();
Reader sourceXml = new StringReader(xml);        
Transformer transformer = tFactory.newTransformer(new StreamSource
(urlXslt));    
transformer.setParameter("highPref", user.getHighPref());
transformer.setParameter("medPref", user.getMedPref());
transformer.setParameter("lowPref", user.getLowPref());
transformer.transform(new StreamSource(sourceXml),new StreamResult
(transformedXml));  // line exception thrown from




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>