Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filter XML from asp 1

Status
Not open for further replies.

arst06d

Programmer
Joined
Nov 29, 2002
Messages
324
Hi
I have a well-formed XML doc and a XSL doc to display it.
Doing the transformation server side in an asp page as follows:

<%
ShowContactCard("HCS")

function ShowContactCard(RegionCode)
on error resume next

'Load XML
set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = false
'response.write server.mappath("contactCards.xml") & "<br>"
xml.load(server.mappath("contactCards.xml"))
if err then
response.write "An error has occurred at Pos 1 -- " & err.description
err.clear
end if

'Load XSL
set xsl = Server.CreateObject("Microsoft.XMLDOM")
xsl.async = false
'response.write server.mappath("contactCards.xsl") & "<br>"
xsl.load(server.mappath("contactCards.xsl"))
if err then
response.write "An error has occurred at Pos 2 -- " & err.description
err.clear
end if

'Transform file
Response.Write(xml.transformNode(xsl))
if err then
response.write "An error has occurred at Pos 3 -- " & err.description
err.clear
end if


end function
%>

Within the XSL I use <xsl:if ...> to test for a value, which I have at present hardcoded into a <xsl:variable ...> as below:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="

<xsl:template match="/">

<html>
<head>
<title>Contact Cards</title>
</head>

<body>


<xsl:variable name="RegCode" select='"HCC"'/>

<xsl:for-each select="contactCards/Region">
<xsl:if test="RegionCode=$RegCode">
<xsl:value-of select="RegionName"/><br/>
</xsl:if>
</xsl:for-each>

</body>
</html>

</xsl:template>
</xsl:stylesheet>

What I would like to do is pass the variable from the asp function when I do the transformation.

Can anyone help, please?
 
You might check MS documentation on using params in DOM.
However, a quick-fix is:
add this line to your code:
oXSL.selectSingleNode("//*[@name='RegCode']").Text = "HCC"
and make the <xsl:variable> node an empty node:
<xsl:variable name="RegCode"/>
 
That did it - Many Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top