[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Passing params to XSLT from Java - Exception

Subject: Passing params to XSLT from Java - Exception
From: jm0019@xxxxxxxxxxxxxxxxxx
Date: Wed, 4 Dec 2002 12:06:01 +0000
java xslt setparameter
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[@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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.