Jump to content

can pass value to xsl?


nwaynge
 Share

Recommended Posts

hello, can u pass parameter value to xsl?eg...cdcatalog.xml-------------------------------<?xml version="1.0" encoding="ISO-8859-1"?><?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?><!-- Edited with XML Spy v2007 (http://www.altova.com) --><catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd> <cd> <title>Hide your heart</title> <artist>Bonnie Tyler</artist> <country>UK</country> <company>CBS Records</company> <price>9.90</price> <year>1988</year> </cd> <cd> <title>Greatest Hits</title> <artist>Dolly Parton</artist> <country>USA</country> <company>RCA</company> <price>9.90</price> <year>1982</year> </cd></catalog>cdcatalog.xsl----------------------------------------<?xml version="1.0" encoding="ISO-8859-1"?><!-- Edited with XML Spy v2007 (http://www.altova.com) --><xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"> <html> <body> <h2>My CD Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>ID</th> <th>Title</th> <th>Artist</th> </tr> <xsl:for-each select="catalog/cd"> <xsl:if test="price>10"> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> </tr> </xsl:if> </xsl:for-each> </table> </body> </html></xsl:template></xsl:stylesheet>cdcatalog.html----------------------------<html><body><script type="text/javascript">// Load XML var xml = new ActiveXObject("Microsoft.XMLDOM")xml.async = falsexml.load("cdcatalog.xml")// Load the XSLvar xsl = new ActiveXObject("Microsoft.XMLDOM")xsl.async = falsexsl.load("cdcatalog_if.xsl?artist='Bonnie Tyler'")// Transformdocument.write(xml.transformNode(xsl))</script></body></html>//////////////////////////////////////////////i only want to show cdcatalog that the artist name is same as my parameter valuecan i do that?pls help methz

Link to comment
Share on other sites

you can't pass parameters with that version of the MS Parser. You need to update to at least version 4.0, the current is 6.0

			var xmlSource		= 	new ActiveXObject("Msxml2.DOMDocument.4.0")			var xslStyle 		=	new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0")			xmlSource.async 	= 	false			xslStyle.async	=	false			xmlSource.load("cdcatalog.xml")			xslStyle.load("cdcatalog_if.xsl")			xslStyle.setProperty("SelectionNamespaces", "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'")			var objTransformer	=	new ActiveXObject("Msxml2.XSLTemplate.4.0")			objTransformer.stylesheet = xslStyle.documentElement			var objProcessor = objTransformer.createProcessor()			objProcessor.addParameter("artist","Bonnie Tyler","")			objProcessor.input = xmlSource						document.write(objProcessor.transform()

you will need to modify your XSLT to accept the parameter

<?xml version="1.0" encoding="ISO-8859-1"?><!-- Edited with XML Spy v2007 (http://www.altova.com) --><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><!-- added -->	<xsl:param name="artist" />	<xsl:template match="/">		<html>			<body>				<h2>My CD Collection</h2>				<table border="1">					<tr bgcolor="#9acd32">						<th>ID</th>						<th>Title</th>						<th>Artist</th>					</tr><!-- changed -->		<xsl:for-each select="catalog/cd[artist = $artist]">						<xsl:if test="price>10">							<tr>								<td><xsl:value-of select="title"/></td>								<td><xsl:value-of select="artist"/></td>							</tr>						</xsl:if>					</xsl:for-each>				</table>			</body>		</html>		</xsl:template></xsl:stylesheet>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...