SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XML (xsl vs css)

    Hi!

    I have an issue on my asp page, I have an xml script in there and the only style that is being applied to my xml is the css for the entire site

    I did create an xsl file to style the xml but the only way i see that is if I view the xml file outside the asp as an independent file and i see the styles.

    What could be wrong?

    Here is my XML in my ASP:

    Code:
    <%
    //Set the XML Object 
    
    Set objXML = Server.CreateObject("Microsoft.XMLDOM")
    
    //Set Asynchoronous = false
    objXML.async = False
    
    //Load the XML file.
    //User Server.MapPath method is the XML is located in your site.
    //Else you can use the absolute path.
    
    objXML.Load (Server.MapPath("pbtoc.xml"))
    
    //If there is any errors pasring the file the notify
    
    If objXML.parseError.errorCode <> 0 Then
    
    Response.Write "Error Parsing XML"
    
    Response.Write  "Reason :" & objXML.parseError.reason & "Error Line: " & objXML.parseError.line
    
    End If
    
    
    
    Set proprietarybrands = objXML.getElementsByTagName(Request.QueryString("id"))
    
    //Now Iterate through the List and Display
    
     For i = 0 to (proprietarybrands.Length-1)
    	
    
        Response.Write pbrands.item(i).childNodes(0).text & ">" 
    	Response.Write pbrands.item(i).childNodes(1).text & "<br/>"
    	Response.Write pbrands.item(i).childNodes(2).text & ("<img src=""images/download_box.jpg"">") & "<br/>"
    	Response.Write("<b>File Downloads</b>") & "<br/>"
    	Response.Write "Link: " & pbrands.item(i).childNodes(3).text & "<br/>"
    	
    Next
    %>
    Here is the XML
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="pb.xsl"?>
    <csvXml>
    
    <row>
    <aaa>
    
    <main_category>Main</main_category>
    <sub_category>Sub</sub_category>
    <spec_sheet>Product</spec_sheet>
    <sectionnumber>&lt;a href="pb.pdf"&gt;Spec</sectionnumber>
    </aaa>
    </row>
    XSL
    Code:
    <?xml version="1.0" encoding="UTF-8"?><!-- DWXMLSource="/PlumbingHVACDEV2010/pbtoc.xml" -->
    <!DOCTYPE xsl:stylesheet  [
    	<!ENTITY nbsp   "&#160;">
    	<!ENTITY copy   "&#169;">
    	<!ENTITY reg    "&#174;">
    	<!ENTITY trade  "™">
    	<!ENTITY mdash  "—">
    	<!ENTITY ldquo  "“">
    	<!ENTITY rdquo  "”"> 
    	<!ENTITY pound  "&#163;">
    	<!ENTITY yen    "&#165;">
    	<!ENTITY euro   "€">
    ]>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" encoding="UTF-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
    <xsl:template match="/">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>Untitled Document</title>
    </head>
      <html>
      
        <body style="color:#666; font-size:20px">
        <table border="5">
          <tr>
          
          </tr>
          <xsl:for-each select="csvXml/row">
            <tr>
              <td><xsl:value-of select="spec_sheet"/></td>
              <td><xsl:value-of select="sectionnumber"/></td>
            </tr>
          </xsl:for-each>
        </table>
    </body>
    </html>
    </html>
    </xsl:template>
    </xsl:stylesheet>

  2. #2
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In ASP with vbscript language(default unless otherwise specified), the "//" is not a valid comment code.

    use the apostrophe instead.

  3. #3
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by webber123456 View Post
    In ASP with vbscript language(default unless otherwise specified), the "//" is not a valid comment code.

    use the apostrophe instead.
    ok that couldnt be the issue though? i'll change the // out to '

  4. #4
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the other thing I see is that:
    Code ASP:
    Set proprietarybrands = objXML.getElementsByTagName(Request.QueryString("id"))
     
    'Now Iterate through the List and Display
     
     For i = 0 to (proprietarybrands.Length-1)

    should be:

    Code ASP:
    Set pbrands = objXML.getElementsByTagName(Request.QueryString("id"))
     
    'Now Iterate through the List and Display
     
     For i = 0 to (pbrands.Length-1)


    When testing, the other problems I saw are XML and XSL issues - I don't know the answer to those. You can take the those to an XML group who will likely answer them quickly.

  5. #5
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by webber123456 View Post
    ...

    When testing, the other problems I saw are XML and XSL issues - I don't know the answer to those. You can take the those to an XML group who will likely answer them quickly.
    oh 'doh that is just an edit error when i pasted it here... that is correct in my actual code ... ill ask the xml side! thanks

  6. #6
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,030
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    surina777,
    I'm coming in a little late but is it your intention to use ASP to apply xsl against the xml data?

    If so, ASP is fairly well equipped to do that. I've got a nice function that does that over in the funky functions section HERE

    Cheers,
    Andrew
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  7. #7
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by awasson View Post
    surina777,
    I'm coming in a little late but is it your intention to use ASP to apply xsl against the xml data?

    If so, ASP is fairly well equipped to do that. I've got a nice function that does that over in the funky functions section HERE

    Cheers,
    Andrew
    i took a look! i will give it a shot and let you know if it works for me thanks a ton! really appreciate it, this forum is great!!!

  8. #8
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,030
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    No problem at all...
    I used to do quite a bit of xml/xsl with ASP some time ago. It works really well once you get into the xml mindset. Let us know how you make out.
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  9. #9
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I gave this a go this morning and I am getting this error:


    Code:
    Microsoft VBScript runtime error '800a000d'
    
    Type mismatch: 'UBound'
    
    /root/testxml.asp, line 27
    here is the code i pasted into my asp

    Code:
    <%
    Function transformXMLArguments(strXMLDoc, strXSLDoc, arrParams)
    
       	Set xml = Server.CreateObject("MSXML2.FreeThreadedDOMDocument.3.0")
       	xml.async = false
       	xml.load strXMLDoc
    
       	Set xsl = Server.CreateObject("MSXML2.FreeThreadedDOMDocument.3.0")
       	xsl.async = false
      	xsl.load strXSLDoc
    
       	Set template = Server.CreateObject("MSXML2.XSLTemplate")
       	template.stylesheet = xsl
       	set processor = template.createProcessor()
    
       	processor.input = xml
    	
    	For i = 0 to UBound(arrParams)
    		If arrParams(i) <> "" Then
    			processor.addParameter "param" & (i+1), arrParams(i)
    		else
    		response.write "No records found"
    		end if
    
    	Next
    
       	processor.transform()
    
    	transformXMLArguments = (processor.output)
       
       	Set xml = nothing
       	Set xsl = nothing
    	Set template = nothing
        set processor = nothing
       End Function
       
    
    response.write transformXMLArguments(Server.MapPath("text.xml"), Server.MapPath("pb.xsl"), "")
    %>
    where did i go wrong? from what i can tell all i needed to do was put edit where my xml and xsl files are...

  10. #10
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,030
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    It looks like it's getting hung up on the array and I should have put some error trapping in there originally. This is where I think it's getting hung up because there is no array or parameters:

    Code:
        For i = 0 to UBound(arrParams)
            If arrParams(i) <> "" Then
                processor.addParameter "param" & (i+1), arrParams(i)
            else
            response.write "No records found"
            end if
    
        Next
    Update the function with the following and see what happens:


    Code:
    if isarray(arrParams) then
        For i = 0 to UBound(arrParams)
            If arrParams(i) <> "" Then
                processor.addParameter "param" & (i+1), arrParams(i)
            else
            response.write "No records found"
            end if
        Next
    end if
    That way unless there is an array of parameters, the code won't run.

    Give that a run and let me know how it works out for you.
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  11. #11
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that worked wonderfully! thanks

    one last thing i need to get working is being able to only display data associated with an ID

    I had this line in my original code:

    Set proprietarybrands = objXML.getElementsByTagName(Request.QueryString("id"))

    that appeared to be pulling in only the data with that ID, how would i use that line w/your function?

    my url would be "webpage.asp?id=1"

  12. #12
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,030
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    In that case I would pass the ID to the XSL file as a parameter and then use it within the XSL to pull out only the data that relates to the ID number when it processes the XML.

    So you grab the ID and put it in the array:
    Code:
    id = Request.QueryString("id")
    arrArgs = Array(id)
    Then pass it to the function:
    Code:
    response.write transformXMLArguments(Server.MapPath("text.xml"), Server.MapPath("pb.xsl"), arrArgs)
    In the XSLT (XSL) file you'll declare your parameter:
    Code:
    <xsl:param name="param1" /> <!-- ID -->
    Now you have a parameter to use within the stylesheet called $param1. I'm not sure how you want to process your XML using XSLT but you can use a choose statement within a loop to pull all the information that relates to ID. Something along thee lines of <xsl:if test="@ID=$param1">
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  13. #13
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi, i have it all working up until the <xsl: if test... statement

    what is @ID referring to?
    Is it looking for this in the xml file? or in the xml function within the asp?

    i think it is referring to this in the xml file

    if i format my xml file like this:
    Code:
    <?xml version="1.0" standalone="yes"?>
    <proprietarybrands>
        <row>
                <pb id="1111"></pb>
                <product_name>High Efficiency Elongated One-Piece</product_name>        
                <spec_sheet>Specification Sheet</spec_sheet>            
                <product_guide></product_guide>          
                <installation_instructions></installation_instructions>
                <warranty></warranty>
        </row>
        <row>
                <pb id="1114"></pb>
                <product_name>High Efficiency Round Two-Piece - 17</product_name>
                <spec_sheet>Specification Sheet</spec_sheet>
                <product_guide></product_guide>
                <installation_instructions></installation_instructions>
                <warranty></warranty>
        </row>
    </proprietarybrands>
    here is my xsl
    Code:
    <?xml-stylesheet type="text/xsl" href="pb.xsl"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    
    <xsl:template name="hoo" match="/">
      <html>
      <body>
      <xsl:for-each select="proprietarybrands/row">
        <xsl:call-template name="pbtemp">
          <xsl:with-param name="param1" select="pb" />
          <xsl:with-param name="param2" select="product_name" />
        </xsl:call-template>
      </xsl:for-each>
      </body>
      </html>
    </xsl:template>
    
    <xsl:template name="pbtemp">
    
      <xsl:param name="param1" select="'Not Available'" />
      <xsl:param name="param2" select="'Not Available'" />
      <div>
      <xsl:if test="@ID=$param1">
      ID: <xsl:value-of select="$param1" />
      PRODUCT NAME: <xsl:value-of select="$param2" />
      <br />
      </xsl:if>
      </div>
      
    </xsl:template>
    
    </xsl:stylesheet>

    1) "No Records Found" displays at the testxml.asp page
    2) Trying to see if the specific ID value displays the data using a url ... testxml.asp?id=1111 and it shows a blank page

    3)deleting out the xsl:if test element displays my xml file correctly

  14. #14
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,030
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Sorry, that xsl:if was just for example of how you might test for the ID of an XML node. You'll have to come up with a specific method in order to put it to proper use with your particular XML/XSL.

    Without the <xsl: if test... statement are you getting the results you are looking for or is it just looping out all of the results? If you need some help getting the specific information you need out of the XML doc, I would check with the folks over at the XML forum.

    If it were my XML doc, I would wrap <pb id="xxx"></pb> around the record. Then you can use an XSL if conditional statement to select only the information inside <pb id="xxx"></pb> where xxx = the ID number you are looking for.
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  15. #15
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Without the <xsl: if test... statement
    - it is looping out all the results.

    i have tried wrapping the id around the record but i haven't tried using the xsl if conditional statement with it, so i will give that a go

    thanks again!

  16. #16
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,030
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Sounds good.

    Here's a links to an example of XSLT conditional use:
    http://www.w3schools.com/xsl/el_if.asp

    Also you can use the choose conditional:
    http://www.informit.com/library/cont...ays&seqNum=113
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development


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
  •