[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

ASP/XML - XLINK question

Posted on 2001-08-03
14
Medium Priority
?
163 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

649 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