Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 28th, 2003, 12:10 AM
Authorized User
 
Join Date: Aug 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default XML document "file name"

I wonder if there is a possibility to get the actual xml
document's "file name" in a variable?

I'm dealing with xml documents stored on local disk or share, and
would like to know the document's file name during xslt.

Regards
George
 
Old August 28th, 2003, 03:18 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

I don't know of any mechanism within xsl to find this out, but presumably the process that invokes the transformation knows what the filename is, so can't you just pass the filename in as a parameter?

rgds
Phil
 
Old August 28th, 2003, 04:35 PM
Authorized User
 
Join Date: Aug 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am using the MSXML 3 or 4 parser from VB:

Syntax:
strValue = oXMLDOMNode.transformNode(objStylesheet)

The actual statement:
yDoc.loadXML xdoc.transformNode(xslStyleSheet)

Does anybody know how I can here pass a parameter to the stylesheet execution?

Regards,
George
 
Old August 29th, 2003, 02:15 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to armmarti
Default

IXSLProcessor.addParameter method (MSXML4) achieves that.

Look at this URL: http://msdn.microsoft.com/library/de...th_ac_5pgy.asp

Here the code is different a little, but I hope it will give some guide.

Regards,
Armen
 
Old August 29th, 2003, 03:59 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

George, here's a function I use regularly to run XSL transformations with parameters:
Code:
Sub DoXslt(sXml, sFileXslt, dctParams)
'==============================================================
' Function : DoXslt
' Purpose : performs an XSLT transformation with parameters
' Author : Phil Griffiths
' Parameters : sXml - the xml string
'         : sFileXslt - relative filename of XSLT
'            : dctParams - Scripting.Dictionary containing param name/value pairs
' Globals : Response object
' Return : None - transformation result written to Response
' Mods : PG 16/4/2002 - Initial Version
'==============================================================
    Dim domXml, domXslt, xslt, xslProc, vKey

    If Len(sXml) > 0 And Len(sFileXslt) > 0 Then
        Set domXml = LoadXmlIntoDom(cProgIdMsxml, sXml)
        Set domXslt = LoadXmlFileIntoDom(cProgIdMsxmlFreeThread, Server.MapPath(sFileXslt))

        Set xslt = Server.CreateObject(cProgIdXslTemplate)
        With xslt
            Set .stylesheet = domXslt
            Set xslProc = .createProcessor()
        End With

        With xslProc
            .input = domXml
            .output = Response
            If Not dctParams Is Nothing Then
                For Each vKey in dctParams
                    Call .addParameter(vKey, dctParams(vKey))
                Next
            End If
            .Transform
        End With

        Set xslProc = Nothing
        Set xslt = Nothing
        Set domXml = Nothing
        Set domXslt = Nothing
    End If

End Sub
You'll need these useful supporting functions and constants too
Code:
Const cProgIdMsxml = "MSXML2.DOMDocument.4.0"
Const cProgIdMsxmlFreeThread = "MSXML2.FreeThreadedDOMDocument.4.0"
Const cProgIdXslTemplate = "MSXML2.XSLTemplate.4.0"
Const cProgIdDictionary = "Scripting.Dictionary"

Function LoadXmlIntoDom(sProgId, sXml)
'==============================================================
' Function : LoadXmlIntoDom
' Purpose : loads an xml string into a DOM object
' Author : Phil Griffiths
' Parameters : sProgId - of the XML DOM object to create
'             : sXml - the xml string
' Globals : None
' Return : object specified by sProgId
' Mods : PG 15/4/2002 - Initial Version
'==============================================================
    Set LoadXmlIntoDOM = Server.CreateObject(sProgId)
    LoadXmlIntoDOM.async = False
    Call LoadXmlIntoDOM.loadXML(sXml)
    Call LoadXmlIntoDOM.setProperty("SelectionLanguage", "XPath")

End Function

Function LoadXmlFileIntoDom(sProgId, sXmlFilePath)
'==============================================================
' Function : LoadXmlIntoDom
' Purpose : loads an xml file into a DOM object
' Author : Phil Griffiths
' Parameters : sProgId - of the XML DOM object to create
'         : sXmlFilePath - the path of the xml file
' Globals : None
' Return : object specified by sProgId
' Mods : PG 15/4/2002 - Initial Version
'==============================================================
    Set LoadXmlFileIntoDOM = Server.CreateObject(sProgId)
    LoadXmlFileIntoDOM.async = False
    Call LoadXmlFileIntoDOM.load(sXmlFilePath)
    Call LoadXmlFileIntoDOM.setProperty("SelectionLanguage", "XPath")

End Function
If you put these functions into an include file, then all you need in your asp is something like this to run any transformation with parameters
Code:
Dim dctParams
Set dctParams = Server.CreateObject(cProgIdDictionary)
With dctParams
  .Add "ParamName1", "ParamValue1"
  .Add "ParamName2", "ParamValue2"
  ' etc...
End With
Call DoXslt(sXmlData, "xslt/thefile.xsl", dctParams)

Set dctParams = Nothing
hth
Phil
 
Old August 30th, 2003, 03:20 AM
Authorized User
 
Join Date: Aug 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi all,

thanks a lot for your replies and code samples.

Now I'm quite sure I'll find my way :-)

Regards,
George





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Get XML Document from iFrame rvanandel Ajax 6 April 10th, 2009 05:24 AM
XML document error jaffir BOOK: ASP.NET Website Programming Problem-Design-Solution 2 July 26th, 2005 12:21 PM
Help formatting an XML document!!! jrmsmo XML 2 February 13th, 2004 06:35 PM
xml document androger XML 2 November 19th, 2003 05:52 PM
XML Document Problem Ben Horne XML 5 November 19th, 2003 01:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.