Solved

ASP/XML - XLINK question

Posted on 2001-08-03
14
155 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_
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 100 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Tool to email me when a website changes 29 118
Can not run ASP pages Windows 10 Edge browser. 5 75
INNER JOIN ? 8 41
Questions about this React unit test 4 43
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

912 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now