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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding records in xml that match sring using asp.

Status
Not open for further replies.

guestAsh

Technical User
Feb 27, 2004
65
GB
Hi,

I’m developing a 6 month rolling calendar using asp and the data (for appointments) held in an xml file.

My problem is that i need to search and bring back all records in the xml file for a particular month. At the moment it's kind of doing it, although it's only bring back the 1st record it find. Any idea how i get it to bring back all?

Examples of the code below:





my xml file looks like this:

Code:
<?xml version="1.0"?>
<goodtogreat>
  <agenda>
    <field id="agendaid" taborder="1">
      <field_value>1</field_value>
    </field>
    <field id="month" taborder="2">
      <field_value>January</field_value>
    </field>
    <field id="agendetitle" taborder="3">
      <field_value>Fireside Chat</field_value>
    </field>
    <field id="link" taborder="4">
      <field_value>
      </field_value>
    </field>
    <field id="prority" taborder="5">
      <field_value>1</field_value>
    </field>
  </agenda>
  <agenda>
    <field id="agendaid" taborder="1">
      <field_value>2</field_value>
    </field>
    <field id="month" taborder="2">
      <field_value>March</field_value>
    </field>
    <field id="agendetitle" taborder="3">
      <field_value>December, GP Good to Great Event Party </field_value>
    </field>
    <field id="link" taborder="4">
      <field_value>
      </field_value>
    </field>
    <field id="prority" taborder="5">
      <field_value>1</field_value>
    </field>
  </agenda>

  <agenda>
    <field id="agendaid" taborder="1">
      <field_value>3</field_value>
    </field>
    <field id="month" taborder="2">
      <field_value>March</field_value>
    </field>
    <field id="agendetitle" taborder="3">
      <field_value>Fireside Chat</field_value>
    </field>
    <field id="link" taborder="4">
      <field_value>
      </field_value>
    </field>
    <field id="prority" taborder="5">
      <field_value>1</field_value>
    </field>
  </agenda>
</goodtogreat>

i'm also using a xsl file:

Code:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] version="1.1">
  <xsl:template match="goodtogreat/agenda">

    <ul>
      <li>
 <xsl:value-of select="field[@id='agendetitle']/field_value" disable-output-escaping="yes"/>
    </li></ul> 


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


Tha asp i'm using to load both of theses files and to get the data back is here:

Code:
Function loadagenda(strXMLFile, strXSLFile, strSid)
 
 Dim objXML
 Dim objNode
 Dim objXSL

 set objXML = Server.CreateObject("Microsoft.XMLDOM")
 objXML.async = false

 objXML.load(strXMLFile)
 Set objNode = objXML.SelectSingleNode("goodtogreat/agenda[field/field_value='" & strSid & "']")
if objNode is nothing then
response.Write ""
else 

 set objXSL = Server.CreateObject("Microsoft.XMLDOM")

 objXSL.async = false
 objXSL.load(strXSLFile)
Response.Write objNode.transformNode(objXSL)
 
End If
End Function

your help is much appreciated

cheers

Ash
 
To do a proper job, you have to radically change the way of thinking.

The reason is that to retrieve all the nodes of certain sid, you use selectnodes() method instead of selectsinglenode() method. But the former now returns a collection which will not stand ready to apply transformnode() with the stylesheet as such.

Instead, you have to make the stylesheet transform the document _as a whole_ with some parameter (top-level xsl:param) with value to be fed by the script using addParameter method to pass the sid to the top-level xsl:param. But then the stylesheet would be radically different from what you have conceived.

In the meantime, you sure can use selectnodes() method to get to the collection, and transform one node after another and stitch together to produce a document containing only a unordered (html) list ready to be response.write out. I fear that will be justifiably blamed by those in the profession for producing such a hack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top