?
Solved

print .xml document with ASP

Posted on 2010-08-29
14
Medium Priority
?
389 Views
Last Modified: 2012-05-10
The attached script, print.asp reads an .xml file and displays it in a format and is printable as an inventory list.  It is supposed to group the output in the form by category.
For some reason, as you can see in the attached screen shot, it is not putting all the records for the category <malawi> into the same group.  It does the same thing with <plants>.  What am I doing wrong>
<table border="1" cellpadding="2" cellspacing="0" style="font-family:arial;font-size:12px">
<tr>
	<th>ShipFish2U.com</th>
		
<%
Dim objXML : Set objXML = Server.CreateObject("Msxml2.DOMDocument.6.0")
objXML.ASync = False
objXML.setProperty "SelectionLanguage","XPath"
If Not objXML.Load(Server.MapPath("/product.xml")) Then
	Response.Write "Error loading XML: " & objXML.parseError.reason
	Response.End
End If

Dim dictCats : Set dictCats = Server.CreateObject("Scripting.Dictionary")

Set objResults = objXML.selectNodes("//row[hide!='true']")
If objResults.length > 0 Then
	Dim objNode, objSubNode, strCurrentCat, intCatCount
	strCurrentCat = ""
	intCatCount = 0
	Do
		Set objNode = objResults.nextNode()
		If objNode Is Nothing Then Exit Do
		Set objSubNode = objNode.selectSingleNode("category")
		If Not objSubNode Is Nothing Then
			If Not strCurrentCat = LCase(objSubNode.text) Then
				strCurrentCat = LCase(objSubNode.text)
				Response.Write "<tr><td style=""font-size:16px;font-weight:bold"" colspan=""20"">&nbsp;</td></tr>"
				Response.Write "<tr><td style=""font-size:16px;font-weight:bold"" colspan=""20"";>" & UCase(strCurrentCat) & "&nbsp;</td></tr>"
				Response.Write "<tr style=""font-weight:bold""align:center""><td colspan=""2"">&nbsp;</td><td colspan=""3"">Large</td><td colspan=""3"">Medium</td><td colspan=""3"">Small</td></tr>"
				Response.Write "<tr style=""font-weight:bold""><td colspan=""1"">Scientific Name</td><td colspan=""1"">Common Name</td><td colspan=""1"">Singles</td><td colspan=""1"">Pairs</td><td colspan=""1"">Trios</td><td colspan=""1"">2 Lot</td><td colspan=""1"">4 Lot</td><td colspan=""1"">6 Lot</td><td colspan=""1"">6 Lot</td><td colspan=""1"">9 Lot</td><td colspan=""1"">12 Lot</td></tr>"
			End If
			Response.Write "<tr>"
			Response.Write "<td>" & getNodeValue(objNode.selectSingleNode("pName")) & "&nbsp;</td>"
			Response.Write "<td>" & getNodeValue(objNode.selectSingleNode("pSubName")) & "&nbsp;</td>"
			Response.Write "<td>" & getNodeValue(objNode.selectSingleNode("lPrice1")) & "&nbsp;</td>"
			Response.Write "<td>" & getNodeValue(objNode.selectSingleNode("lPrice2")) & "&nbsp;</td>"
			Response.Write "<td>" & getNodeValue(objNode.selectSingleNode("lPrice3")) & "&nbsp;</td>"
			Response.Write "<td>" & getNodeValue(objNode.selectSingleNode("mPrice1")) & "&nbsp;</td>"
			Response.Write "<td>" & getNodeValue(objNode.selectSingleNode("mPrice2")) & "&nbsp;</td>"
			Response.Write "<td>" & getNodeValue(objNode.selectSingleNode("mPrice3")) & "&nbsp;</td>"
			Response.Write "<td>" & getNodeValue(objNode.selectSingleNode("sPrice1")) & "&nbsp;</td>"
			Response.Write "<td>" & getNodeValue(objNode.selectSingleNode("sPrice2")) & "&nbsp;</td>"
			Response.Write "<td>" & getNodeValue(objNode.selectSingleNode("sPrice3")) & "&nbsp;</td>"
			Response.Write "</tr>"
		End If
	Loop
End If

Function getNodeValue(objNode)
	If Not objNode Is Nothing Then
		getNodeValue=objNode.text
	Else
		getNodeValue=""
	End if
End Function

Set objResults = Nothing
Set objXML = Nothing
%>
</tr>
</table>

Open in new window

print-asp-output.bmp
0
Comment
Question by:akbiro
[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
  • 7
14 Comments
 
LVL 7

Expert Comment

by:mcuk_storm
ID: 33552888
Hi, it would appear that you are missing the XSLT part from the previous solution which is what ordered the XML results by category
0
 
LVL 7

Expert Comment

by:mcuk_storm
ID: 33552900
The code below should work, you will just need to change the path to product-order.xsl  which is the XSL from from the original question
<table border="1" cellpadding="2" cellspacing="0" style="font-family:arial;font-size:12px">
<tr>
	<th>ShipFish2U.com</th>
		
<%
Dim objXSLT : Set objXSLT = Server.CreateObject("Msxml2.DOMDocument.6.0")
objXSLT.ASync = False
objXSLT.setProperty "SelectionLanguage","XPath"
If Not objXSLT.Load(Server.MapPath("/product-order.xsl")) Then
	Response.Write "Error loading XSLT: " & objXSLT.parseError.reason
	Response.End
End If

Dim objXML : Set objXML = Server.CreateObject("Msxml2.DOMDocument.6.0")
objXML.ASync = False
objXML.setProperty "SelectionLanguage","XPath"
If Not objXML.Load(Server.MapPath("/product.xml")) Then
	Response.Write "Error loading XML: " & objXML.parseError.reason
	Response.End
End If

strSortedXML = objXML.transformNode(objXSLT)
If Not objXML.LoadXML(strSortedXML) Then
	Response.Write "Error loading XML: " & objXML.parseError.reason
	Response.End
End If

Dim dictCats : Set dictCats = Server.CreateObject("Scripting.Dictionary")

Set objResults = objXML.selectNodes("//row[hide!='true']")
If objResults.length > 0 Then
	Dim objNode, objSubNode, strCurrentCat, intCatCount
	strCurrentCat = ""
	intCatCount = 0
	Do
		Set objNode = objResults.nextNode()
		If objNode Is Nothing Then Exit Do
		Set objSubNode = objNode.selectSingleNode("category")
		If Not objSubNode Is Nothing Then
			If Not strCurrentCat = LCase(objSubNode.text) Then
				strCurrentCat = LCase(objSubNode.text)
				Response.Write "<tr><td style=""font-size:16px;font-weight:bold"" colspan=""20"">&nbsp;</td></tr>"
				Response.Write "<tr><td style=""font-size:16px;font-weight:bold"" colspan=""20"";>" & UCase(strCurrentCat) & "&nbsp;</td></tr>"
				Response.Write "<tr style=""font-weight:bold""align:center""><td colspan=""2"">&nbsp;</td><td colspan=""3"">Large</td><td colspan=""3"">Medium</td><td colspan=""3"">Small</td></tr>"
				Response.Write "<tr style=""font-weight:bold""><td colspan=""1"">Scientific Name</td><td colspan=""1"">Common Name</td><td colspan=""1"">Singles</td><td colspan=""1"">Pairs</td><td colspan=""1"">Trios</td><td colspan=""1"">2 Lot</td><td colspan=""1"">4 Lot</td><td colspan=""1"">6 Lot</td><td colspan=""1"">6 Lot</td><td colspan=""1"">9 Lot</td><td colspan=""1"">12 Lot</td></tr>"
			End If
			Response.Write "<tr>"
			Response.Write "<td>" & getNodeValue(objNode.selectSingleNode("pName")) & "&nbsp;</td>"
			Response.Write "<td>" & getNodeValue(objNode.selectSingleNode("pSubName")) & "&nbsp;</td>"
			Response.Write "<td>" & getNodeValue(objNode.selectSingleNode("lPrice1")) & "&nbsp;</td>"
			Response.Write "<td>" & getNodeValue(objNode.selectSingleNode("lPrice2")) & "&nbsp;</td>"
			Response.Write "<td>" & getNodeValue(objNode.selectSingleNode("lPrice3")) & "&nbsp;</td>"
			Response.Write "<td>" & getNodeValue(objNode.selectSingleNode("mPrice1")) & "&nbsp;</td>"
			Response.Write "<td>" & getNodeValue(objNode.selectSingleNode("mPrice2")) & "&nbsp;</td>"
			Response.Write "<td>" & getNodeValue(objNode.selectSingleNode("mPrice3")) & "&nbsp;</td>"
			Response.Write "<td>" & getNodeValue(objNode.selectSingleNode("sPrice1")) & "&nbsp;</td>"
			Response.Write "<td>" & getNodeValue(objNode.selectSingleNode("sPrice2")) & "&nbsp;</td>"
			Response.Write "<td>" & getNodeValue(objNode.selectSingleNode("sPrice3")) & "&nbsp;</td>"
			Response.Write "</tr>"
		End If
	Loop
End If

Function getNodeValue(objNode)
	If Not objNode Is Nothing Then
		getNodeValue=objNode.text
	Else
		getNodeValue=""
	End if
End Function

Set objResults = Nothing
Set objXML = Nothing
%>
</tr>
</table>

Open in new window

0
 
LVL 7

Expert Comment

by:mcuk_storm
ID: 33552916
You could also solve this by changing the access -> xml asp code and adding an order by clause to the sql query so it orders it there instead, then you wouldn't need the XSLT sheet.

Change:
  Dim objRecordSet : Set objRecordSet = objConnection.Execute("SELECT * FROM `" & strTableName & "`", objRecordSet)

To:
  Dim objRecordSet : Set objRecordSet = objConnection.Execute("SELECT * FROM `" & strTableName & "` ORDER BY category ASC", objRecordSet)

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:akbiro
ID: 33553302
Again...cool beans...I can't wait to get back to my computer and work on these.  THANKS and THANKS again...I will let you know
0
 

Author Comment

by:akbiro
ID: 33553559
Forgive me. but if I take the first suggestion above, where do I find th xslt code and when I do, I need to name it and somthing like sort.xslt and change the path in the code above to that file?
And, will that sort also alphabetize the records within the group.

Sorry...but this stuff comes slow and hard for me.

Thanks!
0
 
LVL 7

Expert Comment

by:mcuk_storm
ID: 33553599
The XSLT is the sort.xsl one from the question:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/XML/Q_26420449.html#a33495884

If you add that in and change the path that should solve the sorting problem
0
 

Author Comment

by:akbiro
ID: 33553656
It worked PERFECTLY AGAIN...is there a way to add to that sort xslt so that the output is sorted by group and then display in alphabetical order?  Can it be added to the sort script
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="/">
		<rows>
			<xsl:for-each select="//row[hide!='true']">
				<xsl:sort select="category"/>
				<xsl:copy-of select="."/>
			</xsl:for-each>
		</rows>
	</xsl:template>
</xsl:stylesheet> 

Open in new window

0
 
LVL 7

Expert Comment

by:mcuk_storm
ID: 33553677
It should already do that by default, but adding order="ascending" to the xsl:sort element as below may fix it:-
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="/">
		<rows>
			<xsl:for-each select="//row[hide!='true']">
				<xsl:sort select="category" order="ascending" />
				<xsl:copy-of select="."/>
			</xsl:for-each>
		</rows>
	</xsl:template>
</xsl:stylesheet> 

Open in new window

0
 

Author Comment

by:akbiro
ID: 33553758
It is not sorting the output, IN the groups Alphabetically
0
 
LVL 7

Expert Comment

by:mcuk_storm
ID: 33553897
do you want it sorted by pSubName or pName within the categories?
0
 

Author Comment

by:akbiro
ID: 33554479
pName
0
 
LVL 7

Accepted Solution

by:
mcuk_storm earned 2000 total points
ID: 33554556
This is now adding a second sort condition, so it should sort by category first then by pName, the below code should replace the current xsl file
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="/">
		<rows>
			<xsl:for-each select="//row[hide!='true']">
				<xsl:sort select="category" order="ascending" />
				<xsl:sort select="pName" order="ascending" />
				<xsl:copy-of select="."/>
			</xsl:for-each>
		</rows>
	</xsl:template>
</xsl:stylesheet> 

Open in new window

0
 

Author Comment

by:akbiro
ID: 33557275
That almost got it.  What about this straggler,..see image.  THANKS!!!!!!
sort-alpha2.bmp
0
 

Author Closing Comment

by:akbiro
ID: 33611990
Thank you very much...this is terrific...it is working perfectly.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

801 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