?
Solved

ASP/XML - XLINK question

Posted on 2001-08-03
14
Medium Priority
?
160 Views
Last Modified: 2013-11-19
I have an XML file that looks like this

<?xml version="1.0"?>
<Categories xmlns="http://www.microsoft.com">
<Category>
 <CatName>Services</CatName>
 <CatCount>1226</CatCount>
</Category>
<Category>
 <CatName>QC Motors</CatName>
 <CatCount>756</CatCount>
</Category>
</Categories>

and my XSL file looks like this

<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
        <TABLE BORDER="0">
          <xsl:for-each select="//Category">
            <TR>
              <TD><xsl:value-of select="CatName"/> (<xsl:value-of select="CatCount"/>)</TD>
            </TR>
          </xsl:for-each>
        </TABLE>
  </xsl:template>
</xsl:stylesheet>

and my .asp file looks like this:

Dim xmldoc
Dim xsldoc

Set xmldoc = Server.CreateObject("MSXML2.DOMDocument")
Set xsldoc = Server.CreateObject("MSXML2.DOMDocument")

XML = server.MapPath ("CategoryList.XML")
XSL = server.MapPath ("CategoryList.XSL")

xmldoc.load XML
if xmldoc.parseerror.errorcode <> 0 then
  Response.Write "Error loading XML Document :" & "<BR>"
  Response.Write "----------------------------" & "<BR>"
  Response.Write "Error Code : " & xmldoc.parseerror.errorcode & "<BR>"
  Response.Write "Reason : " & xmldoc.parseerror.reason & "<BR>"
  Response.End
End If

xsldoc.load XSL
if xsldoc.parseerror.errorcode <> 0 then
  Response.Write "Error loading XSL Document :" & "<BR>"
  Response.Write "----------------------------" & "<BR>"
  Response.Write "Error Code : " & xsldoc.parseerror.errorcode & "<BR>"
  Response.Write "Reason : " & xsldoc.parseerror.reason & "<BR>"
  Response.End
End If

Response.Write xmldoc.TransformNode(xsldoc)
%>

All I want to do in the .asp file
is make a hyperlink that goes sends the XML as part of querystring through a hyperlink

Example:
HTML should come out as

<tr><td><a href="browse.asp?ID=Servers">Servers</a> (1226)</td></tr>

Can anyone help making it simple -- I don't understand XML at all?
0
Comment
Question by:qcbam_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 2
14 Comments
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6350064
I understand ASP and XML, but I'm not sure what you want exactly... What exactly do you want where?  Do you want the ASP to redirect to the other browse.asp?
0
 

Author Comment

by:qcbam_
ID: 6350148
Actually,
  This is the problem.

I can display the data with no problems.

The problem is, specifically, the <A href="somewhereID=[data]">

I am getting an error that says, I cant use a "<" in an attribute.

(I am trying to update the style sheet to place a hyperlink that points to browse.com with an querysting of ID (the value of ID ... IS the Name of the category).
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6350171
You have to define markup as CDATA.  To do this you will need to make sure the XML conforms to a DTD.

Here is an example of a Internal DTD

<?xml version="1.0"?>
<!DOCTYPE Cases [
<!ELEMENT Case (CaseNbr,CaseDesc,Customer)>
<!ELEMENT CaseNbr (#PCDATA)>
<!ELEMENT CaseDesc (CDATA)>
<!ELEMENT Customer (CustomerFirstName,  
                CustomerMiddleInitial, CustomerLastName,
                CustomerServiceAddress)>
<!ELEMENT CustomerFirstName (#PCDATA)>
<!ELEMENT CustomerMiddleInitial (#PCDATA)>
<!ELEMENT CustomerLastName (#PCDATA)>
<!ELEMENT CustomerServiceAddress (Address1,Address2,
                                      City,State,Zip)>
<!ELEMENT Address1 (CDATA)>
<!ELEMENT Address2 (CDATA)>
<!ELEMENT City (CDATA)>
<!ELEMENT State (CDATA)>
<!ELEMENT Zip (CDATA)>
]>
<Cases>
<Case>
<CaseNbr>400030</CaseNbr>
<CaseDesc>This is Case Desc</CaseDesc>
<Customer>
  <CustomerFirstName>ZZZZ</CustomerFirstName>
  <CustomerMiddleInitial />
  <CustomerLastName>YYYY</CustomerLastName>
  <CustomerServiceAddress>
    <Address1>1036 ICING ST</Address1>
    <Address2 />
    <City>HBG</City>
    <State>PA</State>
    <Zip>12810</Zip>
  </CustomerServiceAddress>
</Customer>
</Case>
</Cases>
0
WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6350173
Work on setting up the DTD, and comment when you need help.
0
 

Author Comment

by:qcbam_
ID: 6350238
Dave,
  Is this what need for a DTD?

<?xml version="1.0"?>
<!ELEMENT Categories  (Category+)>
<!ELEMENT Category  (CatName , CatCount)>
<!ELEMENT CatName  (#PCDATA)>
<!ELEMENT CatCount  (#PCDATA)>
 
in a previous comment I got a reply that seems to make sense to me..

to use this code in my stylesheet:
<a href="browse.asp?ID="{CatName}"/>">
  <xsl:value-of select="CatName"/>
</a> (<xsl:value-of select="CatCount"/>)

This is intuitive enough to understand.
However, I am getting an error that says Required Whitespace Missing...

Now the code is exactly what I sent (I cut & pasted), and I changed the stylesheet (in between the <TD>'s) to reflect the code above.

0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6350323
Close...

Here ya go

<?xml version="1.0"?>
<!DOCTYPE Categories [
<!ELEMENT Category  (CatName , CatCount)>
<!ELEMENT CatName  (#PCDATA)>
<!ELEMENT CatCount  (#PCDATA)>
]>
<Categories xmlns="http://www.microsoft.com">
<Category>
<CatName>Services</CatName>
<CatCount>1226</CatCount>
</Category>
<Category>
<CatName>QC Motors</CatName>
<CatCount>756</CatCount>
</Category>
</Categories>
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6350328
But if you are going to put in </Markup>

You will need something like

<?xml version="1.0"?>
<!DOCTYPE Categories [
<!ELEMENT Category  (CatName , CatCount)>
<!ELEMENT CatName  (#CDATA)>
<!ELEMENT CatCount  (#CDATA)>
]>
<Categories xmlns="http://www.microsoft.com">
<Category>
<CatName>Services</CatName>
<CatCount>1226</CatCount>
</Category>
<Category>
<CatName>QC Motors</CatName>
<CatCount>756</CatCount>
</Category>
</Categories>
0
 

Author Comment

by:qcbam_
ID: 6350386
Thanks for your help Dave.

This is what my XML file looks like now:

<?xml version="1.0"?>
<!DOCTYPE Categories [
<!ELEMENT Categories (Category+)>   (<-- It made me use)
<!ELEMENT Category  (CatName , CatCount)>
<!ELEMENT CatName  (#PCDATA)>
<!ELEMENT CatCount  (#PCDATA)>
]>
<Categories>
<Category>
<CatName>Services</CatName>
<CatCount>1226</CatCount>
</Category>
<Category>
<CatName>QC Motors</CatName>
<CatCount>756</CatCount>
</Category>
</Categories>

And My XSL:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
        <TABLE BORDER="0">
               <xsl:for-each select="//Category">
                <TR>
                    <TD><a href="browse.asp?ID={CatName}"><xsl:value-of select="CatName"/></a> (<xsl:value-of select="CatCount"/>)</TD>
                </TR>
               </xsl:for-each>
        </TABLE>
  </xsl:template>
</xsl:stylesheet>

AND My ASP

<%
Dim xmldoc
Dim xsldoc

Set xmldoc = Server.CreateObject("MSXML2.DOMDocument")
Set xsldoc = Server.CreateObject("MSXML2.DOMDocument")

XML = server.MapPath ("CategoryList.XML")
XSL = server.MapPath ("CategoryList.XSL")

xmldoc.load XML
if xmldoc.parseerror.errorcode <> 0 then
  Response.Write "Error loading XML Document :" & "<BR>"
  Response.Write "----------------------------" & "<BR>"
  Response.Write "Error Code : " & xmldoc.parseerror.errorcode & "<BR>"
  Response.Write "Reason : " & xmldoc.parseerror.reason & "<BR>"
  Response.End
End If

xsldoc.load XSL
if xsldoc.parseerror.errorcode <> 0 then
  Response.Write "Error loading XSL Document :" & "<BR>"
  Response.Write "----------------------------" & "<BR>"
  Response.Write "Error Code : " & xsldoc.parseerror.errorcode & "<BR>"
  Response.Write "Reason : " & xsldoc.parseerror.reason & "<BR>"
  Response.End
End If

Response.Write xmldoc.TransformNode(xsldoc)
%>




Everything works great except in the hyperlink -- it doesn't replace the data..

I feel stupid because I am not understanding this..

I do appreciate your help -- greatly!

Bill



0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6350440
Are you talking about this link?

<<Categories xmlns="http://www.microsoft.com">>>
0
 

Author Comment

by:qcbam_
ID: 6350455
no.

When I run my .asp script

I get 2 lines

Services (1226)
QC Motors (756)

Where Services  and QC Motors are underlined.

The link to both of these points to :

the same place, browse.asp?ID={CatName}

they should point to

browse.asp?ID=Services
browse.asp?ID=QC Motors
(respectively)

Its just filling in the part after ID= that I can't figure out.

0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6350463
Ok, I'll have a chance to play with it in a bit...
0
 
LVL 27

Accepted Solution

by:
BigRat earned 400 total points
ID: 6350555
Currently you have :-

<TD><xsl:value-of select="CatName"/> (<xsl:value-of select="CatCount"/>)</TD>

which produces :-

<TD>Services(1226)</TD>

and you want :-

<td><a href="browse.asp?ID=Servers">Servers</a> (1226)</td>

WHERE I PRESUME "Servers" MEANS "Services" ??? In which case the xsl is :-

<TD><A><xsl:attribute name="href">browse.asp?ID=<xsl:value-of select="CatName"/></xsl:attribute><xsl:value-of select="CatName"/></A> (<xsl:value-of select="CatCount"/>)</TD>

The <A> .... </A> bit says construct an "A" node. The <xsl:attribute> says add an attribute to the "current node in the output (ie: the A node). The name="href" bit gives the NAME of the attribute. The bit between <xsl:attribute> and </xsl:attribute>, ie the data bit, determines what goes in the "href". This consists of the fixed string "browse.asp?ID=" and the contents (value-of) the CatName node from the <xsl:value-of>.

HTH

PS: I don't like all this cat business. It worries me!
0
 

Author Comment

by:qcbam_
ID: 6350563
In this case the rat got the cat!

Thanks VERY VERY Much --
It works like a charm!

And I would like thank Dave and others for their help.

0
 
LVL 27

Expert Comment

by:BigRat
ID: 6351276
I just happened to be in the area. If you ever again have any questions regarding XML/XSL place them in the XML area. I frequent that area more often. Anyway, a pleasure!
0

Featured Post

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question