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 16th, 2005, 02:14 PM
Banned
 
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default Pass parameter from XSLT to ASP.NET

My setup:
XML > XSLT > ASP.NET (using transformNode method)

My problem:
Is it possible to pull an XSLT parameter into the transformed ASP.NET page? If so, how do you do it?

Details:
I'm trying to create a dynamic page header using an XSLT stylesheet's parameter that's passed to an ASP.NET page using the transformNode method. This is what I have, but obviously it's not working:

1) XSLT stylesheet
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" indent="yes"/>
<xsl:param name="par_pageheader" select="'Forms #38; Document'" />
    <xsl:template match="/">
        <div id="screenleft">
            <xsl:value-of select="$par_pageheader" />
        </div>
    </xsl:template>
</xsl:stylesheet>
2) ASP.NET page
Code:
<%'Load XML
Dim xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = false
xml.load("xmldoc.xml")

'Load XSL
Dim xsl = Server.CreateObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load("xsldoc.xsl")

'XSLT variable
Dim pageHeader = xsl.selectSingleNode("//xsl:param[@name='par_pageheader']")

'Transform file
Response.Write(xml.transformNode(xsl))

'Display page header from XSLT
Response.Write(pageHeader)%>
I don't receive any error messages with this setup, but the parameter doesn't get displayed, and I'm not sure why. Hopefully someone can see what I'm doing wrong. Thanks for any help.

KWilliams
 
Old August 17th, 2005, 02:08 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

There are a number of issues with your code:
  • Why are you using COM in ASP.NET? The XmlDom is deprecated in this scenario and the .NET transforms are as easy to use.
  • If you must use COM then either install the latest parser, version 4 and use
    Code:
    Server.CreateObject("Msxml2.DomDocument.4.0")
    or use version 3
    Code:
    "Msxml2.DomDocument.3.0"
    in which case you will have to specify that you are using XPath for queries
    Code:
    xsl.SetProperty "SelectionLanguage", "XPath"
    By using the older prog id you cannot be sure which version you are getting and you will be forced to use XSLPattern selection language which is no longer supported and quite different to XPath
  • Once all this is sorted you need to let the parser know what namespace is represented by "xsl"
    Code:
    xsl.SetProperty "SelectionNamespaces", "xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"""
  • I would also suggest you look at the XML SDK for the addParameter method which is the recommended way to set param elements

--

Joe (Microsoft MVP - XML)
 
Old August 17th, 2005, 08:29 AM
Banned
 
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:There are a number of issues with your code:
Why are you using COM in ASP.NET? The XmlDom is deprecated in this scenario and the .NET transforms are as easy to use.
As I stated in a previous post, that's because I used the transformNode method provided on the W3Schools website. If you know of a just as simple setup that uses .NET, please let me know.

Quote:
quote:If you must use COM then either install the latest parser, version 4 and use
Server.CreateObject("Msxml2.DomDocument.4.0")
      or use version 3
"Msxml2.DomDocument.3.0"
      in which case you will have to specify that you are using XPath for queries
xsl.SetProperty "SelectionLanguage", "XPath"

By using the older prog id you cannot be sure which version you are getting and you will be forced to use XSLPattern selection language which is no longer supported and quite different to XPath

Once all this is sorted you need to let the parser know what namespace is represented by "xsl"

xsl.SetProperty "SelectionNamespaces", "xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"""

I would also suggest you look at the XML SDK for the addParameter method which is the recommended way to set param elements
That's all well and good. If you can give me some good examples of how to use the .NET version of the transformNode method, please do. I do want to use what works best, but as a newbie, I'm only using what is shown on supposedly up-to-date XML/XSLT/ASP.NET tutorials. Please point me in the right direction. Thanks.

KWilliams
 
Old August 17th, 2005, 11:56 AM
Banned
 
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, I found a great article through Microsoft's site on MSXML.DOMDocument and setting parameters from an XSLT stylesheet at http://msdn.microsoft.com/library/de...ml06192000.asp.

But unfortunately I'm running into a strange result. This is my code:
Code:
<%
'Declare XML and XSL file paths
Dim xmlURL As String, xslURL As String
xmlURL = "xmlDoc.xml"
xslURL = "xslDoc.xsl"

'Pull in pageheaderNode parameter
Dim addRecordFilter = CreateObject("MSXML2.DOMDocument")
addRecordFilter.async = false
addRecordFilter.load(xslURL)

Dim pageheaderNode = addRecordFilter.selectSingleNode("//xsl:param[@name='par_pageheader']")

Response.Write("<html><head>")
Response.Write("<title>")
Response.Write(pageheaderNode)
Response.Write("</title>")
Response.Write("</head><body>")

'Load XML
Dim xml = Server.CreateObject("MSXML.DOMDocument")
xml.async = false
xml.load(xmlURL)

'Load XSL
Dim xsl = Server.CreateObject("MSXML.DOMDocument")
xsl.async = false
xsl.load(xslURL)

'Transform file
Response.Write(xml.transformNode(xsl))

Response.Write("</body></html>")
%>
And this is the output:
Code:
<html>
<head>
<title>System.__ComObject</title>
<body>...</body>
</html>
Am I missing something?

KWilliams





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Pass Parameter to Sub Report in asp.net 2.0 jawad Ahmed Crystal Reports 2 March 1st, 2008 02:17 AM
how to pass parameter in crystal rpt using vb.net pk999a1 BOOK: Professional Crystal Reports for VS.NET 0 July 17th, 2007 01:00 AM
Pass null value to Crystal parameter through .net sachin.bashetti Crystal Reports 0 November 28th, 2006 10:23 AM
XSLT Parameter to ASP.NET Variable kwilliams XSLT 9 February 9th, 2006 04:27 PM





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