post into xslt to change the outcome

Discussion in 'XML' started by nickjtew@gmail.com, Oct 31, 2006.

  1. Guest

    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
    , Oct 31, 2006
    #1
    1. Advertising

  2. wrote:

    > 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.



    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Oct 31, 2006
    #2
    1. Advertising

  3. <> wrote in message
    news:...
    > 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
    Dimitre Novatchev, Nov 1, 2006
    #3
  4. Guest

    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
    , Nov 2, 2006
    #4
  5. 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

    <> wrote in message
    news:...
    > 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
    >
    Dimitre Novatchev, Nov 2, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. przemek drochomirecki

    undefined outcome

    przemek drochomirecki, Jun 13, 2005, in forum: C++
    Replies:
    9
    Views:
    382
    Jacek Dziedzic
    Jun 14, 2005
  2. Dan Kohn
    Replies:
    0
    Views:
    103
    Dan Kohn
    Jan 19, 2006
  3. Pugi!
    Replies:
    2
    Views:
    96
    Steve
    Feb 12, 2007
  4. apparker
    Replies:
    10
    Views:
    368
    apparker
    Apr 3, 2007
  5. cerr
    Replies:
    1
    Views:
    126
    Piet van Oostrum
    Aug 16, 2013
Loading...

Share This Page