RE: [xsl] Passing parameters from ASP to XSL

Subject: RE: [xsl] Passing parameters from ASP to XSL
From: "Newman, Todd" <ToddNewman@xxxxxxxxxxxxxxxx>
Date: Mon, 19 Mar 2001 12:05:36 -0500
Here is how I've passed parameters into XSL from ASP.

------------ Here's the ASP -----------
Dim xml, xsl
Dim XSLTemplate
Dim proc
	'put the XML in an object
	Set xml = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
	xml.async = False
	xml.loadXML XMLSourceFile

	'Load the XSL into an object
	Set xsl = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
	xsl.async = False
	xsl.Load Server.MapPath(XSLSourceFile)

	'add parameters to the xsl
	Set XSLTemplate = Server.CreateObject("MSXML2.XSLTemplate")
	Set XSLTemplate.stylesheet = xsl

	Set proc = XSLTemplate.createProcessor

	' Set the source of the data
	proc.input = xml
	proc.addParameter ParameterName, ParameterValue
	'more parameters...
	proc.Transform
	Response.Write proc.output

	'clean up
	Set xml = Nothing
	Set xsl = Nothing
	Set proc = Nothing
	Set XSLTemplate = Nothing

---------- Here are the key parts of the XSL ----------
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">

	<xsl:param name="SID" select="/.."/>
	[other parameters...]
	<xsl:output method="html" indent="yes"/>

	<xsl:template match="/">
		<p/>
		<table cellspacing="0" cellpadding="1" border="0">
			<xsl:apply-templates select="//Holding"/>
		</table>
		<xsl:call-template name="NextPrevLinks"/>
	</xsl:template>

	[Other Templates...]

</xsl:stylesheet>

-----Original Message-----
From: junx@xxxxxx [mailto:junx@xxxxxx]
Sent: Saturday, March 17, 2001 6:03 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Passing parameters from ASP to XSL


Hi there,

I'm fairly new to XSL and ASP, too. After hours, I managed to transform a
XML document into an HTML document using ASP and XSL. Now, I'm trying to
pass a
parameter from the ASP to the XSL-File (background: I have an article in the
XML-File and I want to render only one page at a time to the browser, the
parameter will specify which page). I've got two problems:
First, I tried an example from the mulberry list archive, but it doesn't
work from ASP-side.

	Set template=createObject("MSXML2.XSLTemplate")
	Set template.stylesheet=addRecordFilter
	Set processor=template.createProcessor
	processor.input=stubDoc

	for each qs in Request.QueryString()
		processor.AddParameter qs,Request.QueryString(qs)
	next

In the second line of code, the processor says, that an object is needed. 

Second, I'm using PWE and MSXML3 to do the transformations. I used the
namespace http://www.w3.org/TR/WD-xsl and it works fine, renders a ToC and
highlights one of the items, selected by and constant integer (this will be
replaced
by the passed parameter, I thought):

<?xml version="1.0"?>
<HTML xmlns:xsl="http://www.w3.org/TR/WD-xsl";>
<HEAD>
    <LINK REL="stylesheet" TYPE="text/css" HREF="style.css"/>
</HEAD>
<BODY>
<!-- CUT THE TOC FROM HERE ON --> 
    <UL ID="toc">
    <xsl:for-each select="article/chapter">
      <LI>
      <xsl:choose>
        <xsl:when test="context()[2]">
          <SPAN>
            <xsl:attribute
name="class">subtitle_small_active</xsl:attribute>
            <xsl:value-of select="title"/>
          </SPAN>
        </xsl:when>
        <xsl:otherwise>
          <A>
            <xsl:attribute name="class">subtitle_small</xsl:attribute>
            <xsl:attribute
name="HREF">#H<xsl:eval>formatIndex(childNumber(this),"1")</xsl:eval></xsl:a
ttribute>
            <xsl:value-of select="title"/>
          </A>
        </xsl:otherwise>
      </xsl:choose>
      </LI>
    </xsl:for-each>
    </UL>
<!-- TOC ENDS HERE -->

</BODY>
</HTML>

I've read, that passing parameters are only working with the namespace
http://www.w3.org/1999/XSL/Tranform, but if I change the namespace to this,
it
says, that I cannot use HTML within this namespace. If I use <xsl:param>
within
the namespace given in the sample source above, it says, that I may not use
the <xsl:param>. Frustrating, I think.

I think, I need a good pointer into the right direction now. What do I have
to change to insert a param into the xsl and how do I add the parameter's
value from the ASP's side? Any examples on the web that will run on my
Personal
Web Server and MSXML3? I have to use these tools because of an assessment
for
my university.

Any comments are highly appreciated

yours
Sebastian Will

-- 
Sent through GMX FreeMail - http://www.gmx.net


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

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


Current Thread