• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 355
  • Last Modified:

ASP + XML + XSL

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
my8817
Asked:
my8817
  • 6
  • 5
  • 4
1 Solution
 
sandaruwanCommented:
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
 
my8817Author Commented:
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
 
sandaruwanCommented:
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
AlfaNoMoreCommented:
<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
 
AlfaNoMoreCommented:
<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
 
sandaruwanCommented:
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
 
AlfaNoMoreCommented:
didn't realise those functions were MSXML3 specific. Seem so damn useful?
0
 
sandaruwanCommented:
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
 
my8817Author Commented:
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
 
sandaruwanCommented:
Maybe you have to register new dll file. Use regsvr32.

- Sandaruwan -
0
 
AlfaNoMoreCommented:
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
 
my8817Author Commented:
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
 
sandaruwanCommented:
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
 
my8817Author Commented:
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
 
my8817Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 6
  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now