post into xslt to change the outcome

N

nickjtew

Hi,

I need to change the output made by my xsl file depending on what ID is
passed by the user in the browser.

The user will need to click links, eg,
http://xxx.com/blah.xml?articleid=245

The itemid will then need to be passed to the xsl, and only the article
with that id will be shown.

I've searched the web for some answers, but i cant find anything. Im
starting to believe this cant be done. Is there an alternative if it
cannot be done?

Thanks for your help
Nick
 
M

Martin Honnen

I need to change the output made by my xsl file depending on what ID is
passed by the user in the browser.

The user will need to click links, eg,
http://xxx.com/blah.xml?articleid=245

The itemid will then need to be passed to the xsl, and only the article
with that id will be shown.

I've searched the web for some answers, but i cant find anything.


The usual solution is server-side XSLT transformation and server-side
processing of the query string part of the URL e.g. you write an ASP (or
e.g. JSP or PHP or CGI) that takes as arguments in the query string the
URL of the stylesheet, the URL of the XML input, and any parameters to
set e.g.

<http://example.com/transform.asp?xsl=sheet1.xml&xml=file1.xml&articleid=245>

then in your server side script you can execute the transformation as
needed.

The only client-side mechanism I know of is a Firefox 2.0 feature to
process special processing instructions as XSLT parameters e.g.
<http://wiki.mozilla.org/XSLT_PI_Parameters>
meaning you can pass parameters form the XML document referencing the
stylesheet. Nevertheless if you wanted to pass parameters form the URL
query string to the processor you would need server-side scripting to
read out the query string and generate those <?xslt-param?> pis.
 
D

Dimitre Novatchev

Hi,

I need to change the output made by my xsl file depending on what ID is
passed by the user in the browser.

The user will need to click links, eg,
http://xxx.com/blah.xml?articleid=245

The itemid will then need to be passed to the xsl, and only the article
with that id will be shown.

I've searched the web for some answers, but i cant find anything. Im
starting to believe this cant be done. Is there an alternative if it
cannot be done?

This can be done with a little bit of scripting (such as with JavaScript)
and some additional information.

Every XSLT processor has its own, implementation way of passing outside
parameters to the stylesheet. Read the vendour's documentation.

For example, for MSXML this will be done using the
IXSLProcessor.AddParameter() method.


Cheers,
Dimitre Novatchev
 
N

nickjtew

Hi,

Thanks for the reply.

I am using asp pages to show the xml with xslt (i can have more than
one xml on the page then). So a normal url will be
http://xxx.com/blah.asp?articleid=15646

The code i use on the asp page to transform the xml/xslt is

<%
xmlf = "feeds/articles.xml"
stylef = "xsl/article.xsl"
set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
set xslDoc = Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.load(Server.Mappath(xmlf))
xslDoc.load(Server.Mappath(stylef))
Response.Write(xmlDoc.transformNode(xslDoc))
%>

Does this help? Could i pass the needed information in using asp?

Thanks
Nick
 
D

Dimitre Novatchev

Here's the example from the MSXML4 SDK -- you must have this documentation!

mk:mad:MSITStore:C:\Program%20Files\MSXML%204.0\doc\xmlsdk4.chm::/htm/xml_mth_ac_5pgy.htm
Dim xslt As New Msxml2.XSLTemplate40
Dim xslDoc As New Msxml2.FreeThreadedDOMDocument40
Dim xmlDoc As New Msxml2.DOMDocument40
Dim xslProc As IXSLProcessor
xslDoc.async = False
xslDoc.resolveExternals = False
xslDoc.Load "sample.xsl"
Set xslt.stylesheet = xslDoc
xmlDoc.async = False
xmlDoc.resolveExternals = False
xmlDoc.Load "books.xml"
If (xmlDoc.parseError.errorCode <> 0) Then
Dim myErr
Set myErr = xmlDoc.parseError
MsgBox("You have error " & myErr.reason)
Else
Set xslProc = xslt.createProcessor()
xslProc.input = xmlDoc
xslProc.addParameter "param1", "Hello"
xslProc.Transform
MsgBox xslProc.output
End IfFile Name: Sample.xsl

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:eek:utput method="html"/>
<xsl:param name="param1"/>
<xsl:template match="/">
The parameter value was: <xsl:value-of select="$param1"/>
</xsl:template>
</xsl:stylesheet>


Cheers,
Dimitre Novatchev
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top