Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old April 5th, 2006, 04:00 PM
Registered User
 
Join Date: Apr 2006
Location: , , USA.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default contains() question...

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:
quote:<xsl:param name="sField"/>
<xsl:param name="sTerm"/>
Here is the list of a couple of XML nodes as an example...
Quote:
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:
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:
quote:<xsl:if test = "contains($sField, $sTerm)">
Quote:
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:
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:
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:
quote:<%@LANGUAGE="VBScript"%>

<%
    dim xslDoc, xmlDoc
    dim sTerm, sField

    sField = Request.QueryString("sField")
    sTerm = Request.QueryString("sTerm")

    set xmlDoc=server.CreateObject("Msxml2.FreeThreadedDOM Document.3.0")
    set xslDoc=server.CreateObject("Msxml2.FreeThreadedDOM Document.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

%>
  #2 (permalink)  
Old April 5th, 2006, 04:58 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
  #3 (permalink)  
Old April 5th, 2006, 09:33 PM
Registered User
 
Join Date: Apr 2006
Location: , , USA.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

  #4 (permalink)  
Old April 6th, 2006, 03:37 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
question maheshraju ASP.NET 2.0 Basics 3 March 13th, 2008 08:54 AM
Question Ashwini Classic ASP Databases 3 January 10th, 2006 07:20 AM
Question? Calibus Classic ASP Databases 8 August 6th, 2004 08:25 AM
a question gorji C++ Programming 2 August 11th, 2003 07:41 AM





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