?
Solved

ASP + XML + XSL

Posted on 2001-09-10
15
Medium Priority
?
349 Views
Last Modified: 2013-11-19
I'm using Windows 2000 Server & Visual Studio Interdev to develop my application. rite now, I have no idea how to proceed on with this XML & XSL things. Hopefully, someone out there could help me with this. thanks!

I have 1 XML file which I wish to transform it to a html file by using XSL. my XML file looks like this.

<?xml version="1.0"?>
<?xml:stylesheet type="text/xsl" href="display.xsl"?>
<list>
     <group>
          <index>01</index>
          <name>Search Engine</name>
          <grpdesc>Searching web.</grpdesc>
          <group id="0101" title="Angelfire" url="www.angel.com" desc="good search engine" by="Louis"/>
          <group id="0102" title="Yahoo" url="www.yahoo.com" desc="best engine" by="Mario"/>
          <group/>
     </group>
     <group>
          <index>02</index>
          <name>Ring Tone</name>
          <grpdesc>H/P ring tones</grpdesc>

          <group id="0201" title="Special" url="www.tones.com" desc="all tones here" by="007"/>

     </group>
     <group>
          <index>03</index>
          <name>Tech</name>
          <grpdesc>Tech</grpdesc>
     </group>
</list>

& I wish it can be transformed into the html which looks like this.

<TABLE bgColor=antiquewhite border=1 cellPadding=1 cellSpacing=1 width="65%">
 
  <TR>
     <TD></TD>
    <TD><B>Group</B></TD>
    <TD><B>Description<B></TD>
    <TD><B>Number of entries<B><TD>
  </TR>
  <TR>
  <TR>
     <TD><INPUT type="checkbox" name=checkbox1></TD>
     <TD><a href="link_lst.asp?txtIndex=01">Search Engine</a></TD>
     <TD><a href="grp_edit.asp?txtIndex=01">Searching web.</a></TD>
     <TD>2</TD>
  </TR>
  <TR>
     <TD><INPUT type="checkbox" name=checkbox2></TD>
     <TD><a href="link_lst.asp?txtIndex=02">Ring Tone</a></TD>
     <TD><a href="grp_edit.asp?txtIndex=02">H/P ring tones</a></TD>
       <TD>1</TD>
  </TR>
  <TR>
     <TD><INPUT type="checkbox" name=checkbox3></TD>
     <TD><a href="link_lst.asp?txtIndex=02">Tech</a></TD>
     <TD><a href="grp_edit.asp?txtIndex=02">Tech</a></TD>
       <TD>None</TD>
  </TR>
 
</TABLE>

pls help...... I need the solution in VB script which is an ASP page.

so, the VB script will look something like this.

Dim objXml
Dim objXsl

Set objXml = Server.CreateObject("MSXML.DOMDocument")
objXml.async = False

Set objXsl = Server.CreateObject("MSXML.DOMDocument")
objXsl.async = False

objXml.load (path:\\Xmlfile.xml)
objXsl.load (path:\\XslFile.xsl)

Response.Write (objXml.transformNode(objXsl))
Set objXml = Nothing
Set objXsl = Nothing

thanks!
0
Comment
Question by:my8817
  • 6
  • 5
  • 4
15 Comments
 
LVL 1

Expert Comment

by:sandaruwan
ID: 6473529
Following xsl file will work fine except it will not get the count of sub groups. I am not sure if you can do it or not. Maybe someone else can help you on that.

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<body>

<TABLE bgColor="antiquewhite" border="1" cellPadding="1" cellSpacing="1" width="65%">
 <TR>
   <TD></TD>
   <TD><B>Group</B></TD>
   <TD><B>Description</B></TD>
   <TD><B>Number of entries</B></TD>
 </TR>
 <xsl:for-each select="list/group">
 <TR>
    <TD><INPUT type="checkbox" name="checkbox1"/></TD>
    <TD><a>
       <xsl:attribute name="href">link_lst.asp?txtIndex=<xsl:value-of select="index"/></xsl:attribute>
       <xsl:value-of select="name"/></a>
    </TD>
    <TD><a>
       <xsl:attribute name="href">link_lst.asp?txtIndex=<xsl:value-of select="index"/></xsl:attribute>
       <xsl:value-of select="grpdesc"/></a></TD>
    <TD>2</TD>
 </TR>
 </xsl:for-each>
</TABLE>  

</body>
</html>

</xsl:template>
</xsl:stylesheet>

To learn more about XSL, refere the following link.

http://www.w3schools.com/xsl/default.asp

- Sandaruwan -
0
 

Author Comment

by:my8817
ID: 6473643
Sandaruwan, thank you for your help. I really appreciate it.

but as u know, my concern is to get this thing done as I dun know how to get it rite. pls help...
0
 
LVL 1

Expert Comment

by:sandaruwan
ID: 6473705
Can you add change the XML file? If so what you have to do is add count as another element in the 'group'.

Then you can use it by
<xsl:value-of select="count"/>

Maybe this is not a good solution. But you can do it for now. I'll try to find a way to get count from the current xml file you have.

- Sandaruwan -
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!

 
LVL 9

Expert Comment

by:AlfaNoMore
ID: 6473830
<xsl:template match="list">
    <xsl:for-each select="group">
        <xsl:value-of select="count(group)" />
    </xsl:for-each>
</xsl:template>

this'll give you a count of how many node's called group are within the first node also called group!!! Not good naming convention there, by the way.
0
 
LVL 9

Expert Comment

by:AlfaNoMore
ID: 6473856
<xsl:template match="list">
    <TABLE bgColor=antiquewhite border=1 cellPadding=1 cellSpacing=1 width="65%">
        <TR>
            <TD></TD>
            <TD><B>Group</B></TD>
            <TD><B>Description<B></TD>
            <TD><B>Number of entries<B><TD>
        </TR>
        <xsl:for-each select="group">
            <TR>
                <TD><INPUT type="checkbox" />
                <xsl:attribute name="name">
                    <xsl:value-of select="'checkbox' + position()" />
                </xsl:attribute>
                </TD>
                <xsl:variable name="index">
                    <xsl:value-of select="index" />
                </xsl:variable>
                <TD><a href="link_lst.asp?txtIndex={$index}"><xsl:value-of select="name" /></a></TD>
                <TD><a href="grp_edit.asp?txtIndex={$index}"><xsl:value-of select="grpdesc" /></a></TD>
                <TD><xsl:value-of select="count(group)" /></TD>
            </TR>
        </xsl:for-each>
    </TABLE>
</xsl:template>
0
 
LVL 1

Accepted Solution

by:
sandaruwan earned 800 total points
ID: 6474288
If you want to use count(), position(), etc... you have to install MSXML 3.0 in the web server. You have to modify your asp file as well.

------ xsl file ---------------------------
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<body>

<TABLE bgColor="antiquewhite" border="1" cellPadding="1" cellSpacing="1" width="65%">
 <TR>
   <TD></TD>
   <TD><B>Group</B></TD>
   <TD><B>Description</B></TD>
   <TD><B>Number of entries</B></TD>
 </TR>
 <xsl:for-each select="list/group">
 <TR>
    <TD><INPUT type="checkbox" name="checkbox{position()}"/></TD>
    <TD><a>
       <xsl:attribute name="href">link_lst.asp?txtIndex=<xsl:value-of select="index"/></xsl:attribute>
       <xsl:value-of select="name"/></a>
    </TD>
    <TD><a>
       <xsl:attribute name="href">link_lst.asp?txtIndex=<xsl:value-of select="index"/></xsl:attribute>
       <xsl:value-of select="grpdesc"/></a></TD>
    <TD><xsl:value-of select="count(group)"/></TD>
 </TR>
 </xsl:for-each>
</TABLE>  

</body>
</html>

</xsl:template>
</xsl:stylesheet>

-------- asp file -------------------------------
<SCRIPT LANGUAGE=vbscript RUNAT=Server>
Dim objXml
Dim objXsl

Set objXml = Server.CreateObject("MSXML2.DOMDocument.3.0")
objXml.async = False

Set objXsl = Server.CreateObject("MSXML2.DOMDocument.3.0")
objXsl.async = False

objXml.load (<xml_file_url>)
objXsl.load (<xsl_file_url>)

Response.Write (objXml.transformNode(objXsl))

Set objXml = Nothing
Set objXsl = Nothing
</SCRIPT>

Hope this will help you.

- Sandaruwan -

0
 
LVL 9

Expert Comment

by:AlfaNoMore
ID: 6474302
didn't realise those functions were MSXML3 specific. Seem so damn useful?
0
 
LVL 1

Expert Comment

by:sandaruwan
ID: 6475710
I have NT4 server installed in my machine. So I had to do like that to execute those functions. Since my8817 is using windows 2000, I am not sure if he had to do like that. Maybe windows 2000 comes with the latest version of MSXML.

Anyway those functions will not work in IE 5.5 as it uses MSXML 2.

- Sandaruwan -
0
 

Author Comment

by:my8817
ID: 6475817
yup, my machine is having MSXML 2.0 only. somehow, I downloaded the latest XML parser 4.0 & installed, it seems makes no different.

Anyhow, I'll try on your methods & keep update to you guys again soon. thanks.
0
 
LVL 1

Expert Comment

by:sandaruwan
ID: 6476002
Maybe you have to register new dll file. Use regsvr32.

- Sandaruwan -
0
 
LVL 9

Expert Comment

by:AlfaNoMore
ID: 6476036
You're probably running both versions (MSXML2 and MSXML3 in side-by-side mode, as apposed to replace). So the default Microsoft.XMLdom call is using v2. To call the new DLL, you'll need to use MSXML3.XMLDOM
0
 

Author Comment

by:my8817
ID: 6476263
ok, my version problem has been rectified & resolved. that's make no issue.

rite now, I need 1 last solution from anyone of u.

I need to validate the checkboxes at client side as client script.

for example,
<SCRIPT LANGUAGE="VBScript">

Private Sub mtdValidateField()

     Dim strErrMsg

        '-- need coding here for validating checkboxes...
         
     If strErrMsg = "" Then          
          window.document.frmAdd.submit()          
     Else
          window.alert (strErrMsg)
     End If
     
End Sub

---- my html code ----

<INPUT type="button" value="Delete" onClick="VBScript:mtdValidateField()">

rite now, I couldn't find the way to validate all my checkboxes in VB script. I need to check whether the checkbox is checked when my users click on the delete button & submit...

thanks, pls help...
0
 
LVL 1

Expert Comment

by:sandaruwan
ID: 6476465
I'm not that much familier with VBScript. But I can give you information on how to do your work.

Since your checkboxes in the html is named like 'checkbox1'... you can use a algorithem like this.

for i = 1 to no_of_checkboxes
   eval ("ret = window.document.frmAdd.checkbox"+ to_string(i) +".checked")
   if (ret) '-- check box i is checked so
      process errmsg
   else '--- checkbox i is not checked
      process errmsg
next i

If you can name all checkboxes in same name (e.g. MyCheckBox) then there is a easy way.

   noOfCkBx = document.frmAdd.MyCheckBox.length
   for i=1 to noOfCkBx
      ret = window.document.frmAdd.MyCheckBox[i].checked

      if (ret) '-- check box i is checked so
         process errmsg
      else '--- checkbox i is not checked
         process errmsg
    next i


Hope you can do it.


- Sandaruwan -
0
 

Author Comment

by:my8817
ID: 6478308
yup, I'm going to name all those checkboxes in a name in order to make it like an array. but I encountered error when I try on your code on the VB script.

it gave me this error.

Object doesn't support this property or method: 'document.frmAdd'

what shall I do to correct this error? many thanks to u...
0
 

Author Comment

by:my8817
ID: 6478345
well, u really helped me a lot.. thank you very much... Have a nice day..

my last problem has been solved. thanks a lot, folks!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

807 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