SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard wdmny's Avatar
    Join Date
    Jul 2000
    Location
    Here
    Posts
    1,010
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help: XML Madness

    I have been working on these forums and instead of directly outputing HTML, each part is output in XML and then formated by XSL. I have run into several problems:

    1. I have an XSL file that works fine as ".xsl" and even as ".asp", as long as there is no code being executed. The XSL that is returned is the exact same thing either way. I need for the file to contain some variable data in it that comes from the settings.

    ASP File Outputting XSL
    Code:
    <%
    Response.ContentType = "text/xml"
    Response.Expires = 0
    Response.Buffer = True
    %>
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
    
    <xsl:template match="/">
    
    <table width="100%" cellspacing="0" cellpadding="1" border="0">
      <tr>
        <td width="05%" align="center"></td>
        <td width="55%" align="center" class="tableheader">Forum</td>
        <td width="10%" align="center" class="tableheader">Topics</td>
        <td width="10%" align="center" class="tableheader">Posts</td>
        <td width="20%" align="center" class="tableheader">Last Post</td>
      </tr>
      <xsl:for-each select="xforums/category">
      <tr>
        <td colspan="5"><xsl:value-of select="ctitle" /></td>
      </tr>
      </xsl:for-each>
    </table>
    
    </xsl:template>
    
    </xsl:stylesheet>


    2. I have the XML below and I need to first loop through the categories and through the forums in each category. I already have it looping through the categories but I don't know what to do about the rest. Note that this is only 1 category with 1 forum, there would be more than one category and more than one forum in each.

    Code:
    <category>
    	<cid>1</cid>
    	<ctitle>Main</ctitle>
    	<cbgcolor>#0080C0</cbgcolor>
    	<forum>
    		<fid>1</fid>
    		<furl>viewforum.asp?FID=1</furl>
    		<ftitle>Main Forum</ftitle>
    		<ftopiccount>0</ftopiccount>
    		<fpostcount>0</fpostcount>
    	</forum>
    </category>

    3. My final question for now involves placing XML data into an HTML tag. I tried the XSL below but it gave an error stating that it couldn't be inside the ""s. I can understand why since the way XML is, I still need to be able to do this though.

    Code:
    <a href="<xsl:value-of select="furl" />">LinkTitle</a>
    Thanks

  2. #2
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try:
    Code:
    <a href="{furl}">{ftitle}</a>
    If that doesn't work, try it the long way round, like so:
    Code:
       <xsl:element name="a">
          <xsl:attribute name="href">
             <xsl:value-of select="furl"/>
          </xsl:attribute>
          <xsl:value-of select="ftitle"/>
       </xsl:element>
    (note that in both cases I have also presumed that the string "LinkTitle" in your XSL example should also be replaced with the contents of the <ftitle> element....!)


    Do either of those fit the bill?


    M@rco
    Last edited by M@rco; May 4, 2002 at 20:42.

  3. #3
    SitePoint Wizard wdmny's Avatar
    Join Date
    Jul 2000
    Location
    Here
    Posts
    1,010
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks M@rco but I am unable to test that because I still have a problem with part 1. I have found that I was using Server.MapPath and therefore my ASP code was never getting executed.

    Even with this, it still is not letting me load my XSL right. It says "Type mismatch: 'objXML.transformNode'" when I try it.

    Code:
    	Set objXSL = Server.CreateObject("Microsoft.XMLHTTP")
    	Set objXML = Server.CreateObject("Microsoft.XMLDOM")
    
    	objXML.LoadXML(strXMLBuffer)
    
    	objXSL.Open "GET", "http://localhost/xforums/xml/" & strXSLDoc & ".asp", False
    	objXSL.Send
    
    	TransformOutput = objXML.transformNode(objXSL)
    
    	Set objXML = Nothing
    	Set objXSL = Nothing
    	strXMLBuffer = Null
    For the .TransformNode part, I initally tried objXSL.responseText and that didn't work either.

    Thanks

  4. #4
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are trying to perform a transform using an XMLHTTP object!!! That'll never work - you need to use another XMLDOM or XSLTemplate object.....!

    Try this:
    Code:
    	Set objHTTP = Server.CreateObject("Microsoft.XMLHTTP")
    	Set objXML = Server.CreateObject("Microsoft.XMLDOM")
    	Set objXSL = Server.CreateObject("Microsoft.XMLDOM")
    
    	objXML.LoadXML(strXMLBuffer)
    
    	objHTTP.Open "GET", "http://localhost/xforums/xml/" & strXSLDoc & ".asp", False
    	objHTTP.Send
    
    	objXSL.LoadXML(objHTTP.ResponseText)
    
    	Set objHTTP = Nothing
    
    	TransformOutput = objXSL.transformNode(objXML)
    
    	Set objXML = Nothing
    	Set objXSL = Nothing
    	strXMLBuffer = Null

    M@rco

  5. #5
    SitePoint Wizard wdmny's Avatar
    Join Date
    Jul 2000
    Location
    Here
    Posts
    1,010
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for all your help M@rco. With your great XML wisdom, do you know of an answer to my final question regarding the multiple forums under multiple categories?

    XML Would Be Somewhat Like This:
    Code:
    <category>
    	<cid>1</cid>
    	<ctitle>Main</ctitle>
    	<cbgcolor>#0080C0</cbgcolor>
    	<forum>
    		<fid>1</fid>
    		<furl>viewforum.asp?FID=1</furl>
    		<ftitle>Main Forum</ftitle>
    		<ftopiccount>0</ftopiccount>
    		<fpostcount>0</fpostcount>
    	</forum>
    	<forum>
    		<fid>2</fid>
    		<furl>viewforum.asp?FID=2</furl>
    		<ftitle>Main Forum</ftitle>
    		<ftopiccount>0</ftopiccount>
    		<fpostcount>0</fpostcount>
    	</forum>
    </category>
    <category>
    	<cid>2</cid>
    	<ctitle>Main</ctitle>
    	<cbgcolor>#0080C0</cbgcolor>
    	<forum>
    		<fid>3</fid>
    		<furl>viewforum.asp?FID=3</furl>
    		<ftitle>Main Forum</ftitle>
    		<ftopiccount>0</ftopiccount>
    		<fpostcount>0</fpostcount>
    	</forum>
    	<forum>
    		<fid>4</fid>
    		<furl>viewforum.asp?FID=4</furl>
    		<ftitle>Main Forum</ftitle>
    		<ftopiccount>0</ftopiccount>
    		<fpostcount>0</fpostcount>
    	</forum>
    </category>
    Thanks again

  6. #6
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    (you're welcome)

    Please post your current XSL code! It should be no problem though - just define another <xsl:template> element to process the forum elements, and then use an <xsl:apply-templates> element to apply the templates (after you have processed the three proceeding elements within the <category>).


    M@rco

  7. #7
    SitePoint Wizard wdmny's Avatar
    Join Date
    Jul 2000
    Location
    Here
    Posts
    1,010
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you so much M@rco. You have solvded all three of my problems. I ended up using the long way for the attribute, but is there a reason for that? The way with the curly braces didn't apply anything, they braces remained.

  8. #8
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Happy to help (as always)!
    What's the "long way"? (post the code)


    M@rco

  9. #9
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this (I think I forgot the apostrophes before):
    <a href="{@furl}">{@ftitle}</a>


    M@rco


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •