Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

XML and XSL

Posted on 2002-07-30
8
Medium Priority
?
409 Views
Last Modified: 2013-11-19
Dear experts,

I'm developing a XML web tool to allow the user to change, add, or delete xml elements and attributes. The following test.xsl can only show the information of one element "command" ( mytree.xml ). It doesn't work if there are more elements of "command" ( mytree2.xml ). I also want to know how to display the details of the element and its' attriubites into the form input fields in the right frame when the user clicks on any node on the left frame. Please advice me with code. Thanks!

****************
test.xsl
****************
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <!--containers-->
    <xsl:template match="*[*]">
    <xsl:variable name="id" select="command" />
    <div>
        <img src="images/collapse.gif" onclick="toggleMenu('{$id}');" name="img{$id}" style="cursor:hand;"/>
        <span class="item">
              <xsl:value-of select="name(.)"/>:  [<xsl:value-of select="@name" />]
      </span>
      <div style="display:none;" id="container{$id}" class="container">
              <xsl:apply-templates select="*" />
      </div>
    </div>
</xsl:template>

<!--leaf objects-->
<xsl:template match="*[not(*)]">
     <div>
        <img src="images/leaf.gif"/>
        <span class="item">
            <xsl:value-of select="name(..)"/>::<xsl:value-of select="name(.)"/>: [<xsl:value-of select="@name"/>]
        </span>
     </div>
   </xsl:template>  
</xsl:stylesheet>
0
Comment
Question by:Amy01
[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
  • 5
  • 3
8 Comments
 

Author Comment

by:Amy01
ID: 7188779
**************
treeTest.html
**************
<html>
   <head>
       <title>Tree Menu Through MSIE Transformation</title>
       <script language="javascript">
     <!--
          var imgExpand = new Image();
          imgExpand.src = "images/expand.gif";
          var imgCollapse = new Image();
          imgCollapse.src = "images/collapse.gif";

          function toggleMenu(szID) {
                var szImage = "img" + szID;
                var img = document.images ? document.images[szImage]  : null;
                var szContainer = "container" + szID;
                var container = document.all ? document.all[szContainer] : document.getElementById ?

document.getElementById(szContainer) : null;
                if (! img || ! container) return;
                     if (container.style.display == "none") {
                            img.src = imgExpand.src;
                            container.style.display = "block";
                     } else {
                            img.src = imgCollapse.src;
                            container.style.display = "none";
                     }
          }
         
          window.onload = init;
          function init() {
               // use the  += operator which appends
               // using the = replaces the innerHTML and removes the reference to the data islands
               // that would generate errors
                 document.body.innerHTML += oXML.transformNode(oXSLT);
          }
     //-->
     </script>
     <style type="text/css">
     <!--
          body {font-family:Verdana;letter-spacing:0.3mm;font-variant:small-caps;font-size:8pt;background:#fffffe;}
          a {text-decoration:none;color:#4682b4;}
          a:hover {text-decoration:underline;color:#800000;}
          div.root, div.container, div.item {padding-left:10px;}
     //-->
     </style>
   </head>
   <body>
     <XML id="oXML" src="mytree.xml"></XML>
     <XML id="oXSLT" src="test.xsl"></XML>
   </body>
</html>
0
 

Author Comment

by:Amy01
ID: 7188780
*******************
modifyXML.html
*******************
<HTML>
    <HEAD>
     <TITLE>Modify XML Document</TITLE>
     </HEAD>
     <BODY>
        <IFRAME ALIGN=LEFT FRAMEBORDER=1 HEIGHT=300  WIDTH=75% MARGINHEIGHT=0 MARGINWIDTH=0 NAME=XMLTree SCROLLING=yes SRC="./folderTreeFrame.jsp">
      </BODY>
</HTML>



********************
XMLTreeFrame.html
********************
<html>
<head>
<title>XMLTree</title>
</head>

<FRAMESET cols="200,*">
  <FRAME src="./treeTest.html" name="treeframe" > 
  <FRAME SRC="./folderTreeBlankFrame.jsp" name="basefrm">
</FRAMESET>

</HTML>


**************
mytree.xml
**************
<?xml version="1.0"?>
  <project name="XML Generator Application">
     <command name="View">
     <codeBase>xmlgenerator.commands.View</codeBase>
     <target name="view">/viewXMLDocument.jsp</target>
        <target name="modify">/modifyXMLDocument.jsp</target>
     <requestparameter get="true" set="false" name="userFile">java.lang.String</requestparameter>
     <requestparameter get="true" set="false" name="action">java.lang.String</requestparameter>
     <requestparameter get="true" set="false" name="xmlDocument">java.lang.String</requestparameter>
     <requestparameter get="true" set="true" name="xmlFile">java.lang.String</requestparameter>
      </command>
</project>

****************
mytree2.html
****************
<?xml version="1.0"?>
  <project name="XML Generator Application">
     <command name="View">
     <codeBase>xmlgenerator.commands.View</codeBase>
     <target name="view">/viewXMLDocument.jsp</target>
        <target name="modify">/modifyXMLDocument.jsp</target>
     <requestparameter get="true" set="false" name="userFile">java.lang.String</requestparameter>
     <requestparameter get="true" set="false" name="action">java.lang.String</requestparameter>
     <requestparameter get="true" set="false" name="xmlDocument">java.lang.String</requestparameter>
     <requestparameter get="true" set="true" name="xmlFile">java.lang.String</requestparameter>
     <requestparameter get="false" set="true" name="msg">java.lang.String</requestparameter>
     <requestparameter get="false" set="true" name="viewList">java.util.Vector</requestparameter>
        <requestparameter get="false" set="true" name="nodes">java.util.Collection</requestparameter>
      </command>
      <command name="Modify">
     <codeBase>xmlgenerator.commands.View</codeBase>
     <target name="view">/viewXMLDocument.jsp</target>
        <target name="modify">/modifyXMLDocument.jsp</target>
     <requestparameter get="true" set="false" name="userFile">java.lang.String</requestparameter>
     <requestparameter get="true" set="false" name="action">java.lang.String</requestparameter>
     <requestparameter get="true" set="false" name="xmlDocument">java.lang.String</requestparameter>
     <sessionattribute get="true" set="true" name="id">java.lang.String</requestparameter>
      </command>
</project>
0
 
LVL 27

Accepted Solution

by:
BigRat earned 140 total points
ID: 7190163
Why the "catch-all" top level template :-

   <!--containers-->
   <xsl:template match="*[*]">


It requires "command" to be a child node, so why not explicitly match command?
0
Stack Overflow Podcast - Developer Story

Welcome to the Stack Overflow podcast recorded Thursday July 20 at Stack Overflow Headquearters in NYC. Your hosts today are podcast regulars Jay Hanlon, David Fullerton, and Ilana Yitzhaki, plus the quite irregular Matt Sherman (Stack Overflow Engineering Manager extraordinaire)

 

Author Comment

by:Amy01
ID: 7190637
It also need catch the element "project"
<?xml version="1.0"?>
 <project name="XML Generator Application">
    <command name="View">
    <codeBase>xmlgenerator.commands.View</codeBase>
    <target name="view">/viewXMLDocument.jsp</target>
       <target name="modify">/modifyXMLDocument.jsp</target>
    <requestparameter get="true" set="false" name="userFile">java.lang.String</requestparameter>
    <requestparameter get="true" set="false" name="action">java.lang.String</requestparameter>
    <requestparameter get="true" set="false" name="xmlDocument">java.lang.String</requestparameter>
    <requestparameter get="true" set="true" name="xmlFile">java.lang.String</requestparameter>
    <requestparameter get="false" set="true" name="msg">java.lang.String</requestparameter>
    <requestparameter get="false" set="true" name="viewList">java.util.Vector</requestparameter>
       <requestparameter get="false" set="true" name="nodes">java.util.Collection</requestparameter>
     </command>
     <command name="Modify">
    <codeBase>xmlgenerator.commands.View</codeBase>
    <target name="view">/viewXMLDocument.jsp</target>
       <target name="modify">/modifyXMLDocument.jsp</target>
    <requestparameter get="true" set="false" name="userFile">java.lang.String</requestparameter>
    <requestparameter get="true" set="false" name="action">java.lang.String</requestparameter>
    <requestparameter get="true" set="false" name="xmlDocument">java.lang.String</requestparameter>
    <sessionattribute get="true" set="true" name="id">java.lang.String</requestparameter>
     </command>
</project>
0
 
LVL 27

Expert Comment

by:BigRat
ID: 7190734
Yes, I appreciate that, but can you tell me why the "catch alls" or if you don't understand me, why the *[*]? What is it meant to match exactly? (Rat is probably not in full form today!)
0
 

Author Comment

by:Amy01
ID: 7201578
*[*] matches any element on the tree except leaf elements.
0
 

Author Comment

by:Amy01
ID: 7210283
Here is my solution:
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <!--containers-->
     
      <xsl:template match="*[*]">
      <xsl:variable name="id" select="*" />
      <div>
           <img src="images/collapse.gif" onclick="toggleMenu('{$id}');" name="img{$id}" style="cursor:hand;"/>
             <span class="item">
                  <xsl:value-of select="name(.)"/>:  [<xsl:value-of select="@name" />]
             </span>
             <div style="display:none;" id="container{$id}" class="container">
                  <xsl:apply-templates select="*" />
             </div>  
        </div>  
     </xsl:template>

     <!--leaf objects-->
     <xsl:template match="*[not(*)]">
     <xsl:variable name="id" />
     <div>
             <img src="images/leaf.gif"/>
             <span class="item">
                   <xsl:value-of select="name(..)"/>::<xsl:value-of select="name(.)"/>: [<xsl:value-of select="@name" />]
             </span>
     </div>
    </xsl:template>
   
</xsl:stylesheet>
0
 
LVL 27

Expert Comment

by:BigRat
ID: 7213967
Interesting...

In the leaf template the  <xsl:variable name="id" />
is unused and redundant.

I must admit I do like the *[not(*)] construct! It appeals to Rat's failble for the obscure!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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.
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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…

721 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