Solved

ASP/XML - XLINK question

Posted on 2001-08-03
14
154 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

762 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

20 Experts available now in Live!

Get 1:1 Help Now