• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 169
  • Last Modified:

ASP/XML - XLINK question

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
qcbam_
Asked:
qcbam_
  • 7
  • 5
  • 2
1 Solution
 
Dave_GreeneCommented:
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
 
qcbam_Author Commented:
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
 
Dave_GreeneCommented:
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
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
Dave_GreeneCommented:
Work on setting up the DTD, and comment when you need help.
0
 
qcbam_Author Commented:
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
 
Dave_GreeneCommented:
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
 
Dave_GreeneCommented:
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
 
qcbam_Author Commented:
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
 
Dave_GreeneCommented:
Are you talking about this link?

<<Categories xmlns="http://www.microsoft.com">>>
0
 
qcbam_Author Commented:
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
 
Dave_GreeneCommented:
Ok, I'll have a chance to play with it in a bit...
0
 
BigRatCommented:
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
 
qcbam_Author Commented:
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
 
BigRatCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now