|
Subject:
|
contains() question...
|
|
Posted By:
|
CyanBlue
|
Post Date:
|
4/5/2006 4:00:34 PM
|
Howdy... :)
First time using the XSL so I might not be making much sense... I hope not though...
Okay... I am using ASP(I am not the ASP guy either) to pass in two variables, sField and sTerm, into the XSL file...
quote: <xsl:param name="sField"/> <xsl:param name="sTerm"/>
Here is the list of a couple of XML nodes as an example...
quote: <?xml version="1.0" encoding="ISO-8859-1"?> <Press> <Release> <title>The Downfall of "Always Connected"</title> <category>MEDIA</category> <source>iMedia Connection</source> <date>March 29, 2006</date> <linkType>WEB</linkType> <linkURL1>http://www.imediaconnection.com/content/8842.asp</linkURL1> <linkURL2></linkURL2> </Release>
<Release> <title>Fourth-graders deliver the news on TV broadcast every morning</title> <category>EDUCATION</category> <source>Kingsport Times-News</source> <date>March 19, 2006</date> <linkType>WEB</linkType> <linkURL1>http://www.timesnews.net/communityArticle.dna?_StoryID=3613155</linkURL1> <linkURL2></linkURL2> </Release>
<Release> <title>You Don't Need A Weatherman... WeatherBug's Strength Lies in its Vast Network of Data</title> <category>GOVERNMENT</category> <source>Federal Computer Week</source> <date>February 27, 2006</date> <linkType>PDF</linkType> <linkURL1>http://www.aws.com/aws_2005/releases/2006/clipping_feb2006_fedcomputerweek.pdf</linkURL1> <linkURL2></linkURL2> </Release> ...
What I am trying to do is to display the nodes that contain 'EDUCATION' for example or 'MEDIA' or the ones whoes date is set to 2005 for example or even the nodes that meets both conditions...
In one of the template, I am trying to filter the data with the contains() function like this...
quote: <xsl:template match="Press/Release"> <xsl:if test = "contains(., $sTerm)">
That attempt searchs the given $sTerm(MEDIA) from everythin in the node, I think...
I can change the '.' to 'category' to search for the specific category, and I can chage that to 'date' to search for specific year, but I cannot make that dynamic... I tried to pass in $sField as either 'category' or 'date' and use this, but I get the error message...
quote: <xsl:if test = "contains($sField, $sTerm)">
quote: Error Type: msxml3.dll (0x80004005) The stylesheet does not contain a document element. The stylesheet may be empty, or it may not be a well-formed XML document. /Coverage/Coverage.asp, line 32
I know I am babbling too much but here is a pseudo code of what I am looking to happen in the XSL document so that I can search for the 'MEDIA' category of all the 2005 records or something... I feel like I am getting the $sField passed in okay but it is not doing the comparison because of the type difference or something...
quote:
if ($sField == null) then $theField = "." else $theField = $sField
<xsl:if test = "contains($theField, $sTerm)">
Any help would be appreciated...
Thanks... :)
CyanBlue
Just in case... This is the content of the XSL file...
quote: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" encoding="iso-8859-1"/> <xsl:param name="sField"/> <xsl:param name="sTerm"/> <xsl:template match="/"> <xsl:apply-templates select="Press/Release"/> </xsl:template>
<xsl:template match="Press/Release"> <xsl:if test = "contains(., $sTerm)"> <p><a href="{linkURL1}" target="_blank"><xsl:value-of select="title"/></a> <xsl:if test = "contains(linkType, 'PDF')"> <xsl:text> </xsl:text><strong>(<xsl:value-of select="linkType"/>)</strong> </xsl:if> <br /><xsl:value-of select="source"/><xsl:text>, </xsl:text><strong><xsl:value-of select="date"/></strong></p> </xsl:if> </xsl:template>
</xsl:stylesheet>
and this is the content of the ASP file...
quote: <%@LANGUAGE="VBScript"%>
<% dim xslDoc, xmlDoc dim sTerm, sField sField = Request.QueryString("sField") sTerm = Request.QueryString("sTerm") set xmlDoc=server.CreateObject("Msxml2.FreeThreadedDOMDocument.3.0") set xslDoc=server.CreateObject("Msxml2.FreeThreadedDOMDocument.3.0") xmldoc.async = false xslDoc.async = false If IsNull(sField) then sField = "." else sField = UCase(sField) end if xmlDoc.load server.mapPath("Coverage.xml") xslDoc.load server.mapPath("Coverage.xsl") Set template = Server.CreateObject("MSXML2.XSLTemplate.3.0") Set template.stylesheet = xslDoc Set proc = template.createProcessor proc.input = xmlDoc If Len(sTerm) < 1 then sTerm = "." else sTerm = UCase(sTerm) end if proc.addParameter "sField", sField proc.addParameter "sTerm", sTerm proc.transform Response.Write proc.output %>
|
|
Reply By:
|
mhkay
|
Reply Date:
|
4/5/2006 4:58:09 PM
|
This story reads to me like someone describing in great detail how they mixed the ingredients for a cake and put it in the oven, and waited two hours, and when they opened the oven door the cake was stone cold. That doesn't suggest a problem with the way the cake was made, the problem is with the oven.
What I mean by that is this message: "The stylesheet does not contain a document element. The stylesheet may be empty, or it may not be a well-formed XML document." suggests strongly that your problem is at the XML level or perhaps at the ASP level, but not at the XSLT level.
Try loading your stylesheet into an XML editor to see if it is well-formed XML. Check that the ASP page is really loading the XML file you think it is...
And I would suggest that you try to establish a more self-contained environment for development and testing. Testing XSLT code, whether client-side or server-side, in its "production" environment is no fun at all: the real error messages that explain what's wrong have a nasty habit of not reaching the person who needs to know. This seems to be a particular problem in the Microsoft world, though it can also happen with servlet containers if you configure them wrong.
Michael Kay http://www.saxonica.com/ Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|
Reply By:
|
CyanBlue
|
Reply Date:
|
4/5/2006 9:33:39 PM
|
Thanks for the reply, Mr. Kay... :)
Yeah... I think I understand what you meant by that analogy...
I can get to see the correct output if I try the whole thing without the sField value... If I type http://localhost/Coverage.asp?sTerm=education, I get to see the list of the items that belong to that category, so I don't think the XML file is malformatted... But if I typpe http://localhost/Coverage.asp?sField=date&sTerm=2005, I get that error message for some reason...
Any help would be appreciated... :)
CyanBlue
|
|
Reply By:
|
mhkay
|
Reply Date:
|
4/6/2006 3:37:06 AM
|
Sorry, I'm afraid you've exhausted my limited knowledge of ASP and MSXML.
Michael Kay http://www.saxonica.com/ Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|