Online Shopping : Computers : Internet : Web : XML : XSL[T] (in IE 5.x)

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

1 of 6 people (17%) answered Yes
Recently 0 of 5 people (0%) answered Yes

Entry

XML: Column order determined by secondary xml data?

Apr 2nd, 2009 07:00
engatoo engatoo, Knud van Eeden, jsWalter,


[I am using IE 5.5, MSXML 3.0, Javascript 1.2]
I have this as a secondary data source...
<titles>
   <display id='num'>Num</display>
   <display id='date'>Time Stamp</display>
   <display id='curr_dest'>Agent</display>
   <display id='media'>display>Channel</display>
   <display id='reason'>Reason</display>
   <display id='comment'>Comments</display>
</titles>
I want to use this as the control for the column order for a table 
display.
The ID attribute above is the NODE name in my main data source.
Any ideas?
Walter
PS: This is my name space...
    <xsl:stylesheet version='1.0' 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-----------------------------------------------------------------------
--- Knud van Eeden - 21 September 2001 - 19:45 ------------------------
Computer: Language: Document processing: XML: Column order determined 
by secondary XML data
[Internet: see also: 
http://www.faqts.com/knowledge_base/view.phtml/aid/6640,
http://www.xmlpitstop.com/default.asp?DataType=SSCMDS]
Let us first have a look at creating a representation of the given 
data.
First I create a row like HTML representation.
Then as a next step, I create a table HTML representation.
Then using XSLT, the primary data will be inserted in this table.
---
Steps: Overview:
1. Have Microsoft Explorer v5.0 or higher installed.
2. Create 3 files, in plain text:
 2.1 Create an XML file, containing your raw data
  2.1.1 Save this file as 'titles.xml'
 2.2 Create a DTD file, containing a description of the structure of 
your raw data
  2.2.1 Save this file as 'titles.dtd'
 2.3 Create an XSL file, containing a possible (HTML) representation 
of 
your raw data
  2.3.1 Save this file as 'titles.xsl'
3. Load the XML file in your browser
4. Check the HTML result
 4.1 Adapt the result to your liking
5. Get the data from the primary database files (with the
   filenames received by reading the value of the 'ID' attribute)
---
Steps: Worked out:
1. Have Microsoft Explorer v5.0 or higher installed.
---
2. Create 3 files, in plain text:
---
 2.1 Create an XML file, containing your raw data
---
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE TITLES SYSTEM "titles.dtd">
<?xml-stylesheet type="text/xsl" href="titles.xsl"?>
<!-- library: (filenamemacro=titles.xml)  -->
<TITLES>
 <DISPLAY ID="num">
  Num
 </DISPLAY>
 <DISPLAY ID="date">
    Time Stamp
 </DISPLAY>
 <DISPLAY ID="curr_dest">
    Agent
 </DISPLAY>
 <DISPLAY ID="media">
    Channel
 </DISPLAY>
 <DISPLAY ID="reason">
    Reason
 </DISPLAY>
 <DISPLAY ID="comment">
    Comments
 </DISPLAY>
</TITLES>
---
 2.1.1 Save this file as 'titles.xml'
---
 2.2 Create a DTD file, containing a description of the structure of 
your raw data
---
<!-- library: (filenamemacro=titles.dtd) [kn, ri, fr, 21-09-2001 
18:09:22] -->
 <!ELEMENT TITLES (DISPLAY+)>
   <!ATTLIST
      DISPLAY
       ID (
        comment |
        curr_dest |
        date |
        media |
        num |
        reason
       )
       #REQUIRED
   >
    <!ELEMENT DISPLAY (#PCDATA)>
---
  2.2.1 Save this file as 'titles.dtd'
---
 2.3 Create an XSL file, containing a possible (HTML) representation 
of 
your raw data
---
In order to get the feeling, I used an earlier made example
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<!-- library: (filenamemacro=titles.xsl) [kn, ri, fr, 21-09-2001 
18:09:17] -->
 <xsl:template
   match="/"
 >
   <xsl:apply-templates/>
 </xsl:template>
 <xsl:template
   match="TITLES">
   <HTML>
    <HEAD>
     <TITLE>
       Titles database
     </TITLE>
    </HEAD>
    <BODY>
     <H3> Overview titles database </H3>
     <BR/>
     <BR/>
     <HR/>
     <HR/>
      <xsl:apply-templates/>
     <HR/>
    </BODY>
   </HTML>
 </xsl:template>
 <xsl:template
   match="DISPLAY"
 >
  <FONT
    SIZE="3"
    COLOR="blue"
  >
   <BR/>
     display:
      <xsl:value-of select="."/>
  </FONT>
  <HR/>
 </xsl:template>
</xsl:stylesheet>
---
which gives the result in your browser:
+------------------------------------------------------------------+
|Overview titles database                                          |
|                                                                  |
|                                                                  |
|                                                                  |
|------------------------------------------------------------------|
|                                                                  |
|------------------------------------------------------------------|
|                                                                  |
|display: Num                                                      |
|------------------------------------------------------------------|
|                                                                  |
|display: Time Stamp                                               |
|------------------------------------------------------------------|
|                                                                  |
|display: Agent                                                    |
|------------------------------------------------------------------|
|                                                                  |
|display: Channel                                                  |
|------------------------------------------------------------------|
|                                                                  |
|display: Reason                                                   |
|------------------------------------------------------------------|
|                                                                  |
|display: Comments                                                 |
|------------------------------------------------------------------|
|                                                                  |
|------------------------------------------------------------------|
+------------------------------------------------------------------+
---
Now this is not exactly what is wanted, so let us adapt this result:
Using the following general problem solving methods:
  1. 'working backwards from the (HTML) result you want'
  2. 'working top down, from the whole to the parts'
---
Applying this 'working backwards':
  You like to have a COLUMN view of the data, so this is the HTML
  source code of what you want, so your XSL has to produce a
  result similar to the below HTML code somehow:
<HTML>
 <!-- (filenamemacro=titles.htm) -->
 <HEAD>
  <TITLE>
    Titles table
  </TITLE>
 </HEAD>
 <BODY
   BGCOLOR="white"
 >
  <TABLE
    BORDER="true"
  >
   <CAPTION
     ALIGN="top"
   >
      Titles table
   </CAPTION>
   <TR>
    <TH> Column1 </TH>
    <TH> Column2 </TH>
    <TH> Column3 </TH>
    <TH> Column4 </TH>
    <TH> Column5 </TH>
    <TH> Column6 </TH>
   </TR>
    <TD> Element11 </TD>
    <TD> Element12 </TD>
    <TD> Element13 </TD>
    <TD> Element14 </TD>
    <TD> Element15 </TD>
    <TD> Element16 </TD>
   <TR>
    <TD> Element21 </TD>
    <TD> Element22 </TD>
    <TD> Element23 </TD>
    <TD> Element24 </TD>
    <TD> Element25 </TD>
    <TD> Element26 </TD>
   </TR>
   <TR>
    <TD> Element31 </TD>
    <TD> Element32 </TD>
    <TD> Element33 </TD>
    <TD> Element34 </TD>
    <TD> Element35 </TD>
    <TD> Element36 </TD>
   </TR>
  </TABLE>
 </BODY>
</HTML>
---
The idea in building up the text you want to generate with XSL, is that
'any text which is not an XSL command is ignored, and passed straight
to your output, thus generating the source code you want'.
So you litter the area around your XSL commands with the source code 
you
want to generate.
---
Determine the constant and variable (that is, depending on the 
elements) parts
in this code:
In this code, determine the constant parts. That is the following
code (what follows further depends on the particular 'display' values):
<HTML>
 <!-- (filenamemacro=titles.htm) -->
 <HEAD>
  <TITLE>
    Titles table
  </TITLE>
 </HEAD>
 <BODY
   BGCOLOR="white"
 >
  <TABLE
    BORDER="true"
  >
   <CAPTION
     ALIGN="top"
   >
      Titles table
   </CAPTION>
    ... here comes the other data ...
  </TABLE>
 </BODY>
</HTML>
---
So you can write the following match for say the '<titles>' node:
 <xsl:template
   match="TITLES">
    <HTML>
     <!-- (filenamemacro=titles.htm) -->
     <HEAD>
      <TITLE>
        Titles table
      </TITLE>
     </HEAD>
     <BODY
       BGCOLOR="white"
     >
      <TABLE
        BORDER="true"
      >
       <CAPTION
         ALIGN="top"
       >
          Titles table
       </CAPTION>
        <xsl:apply-templates/>
      </TABLE>
     </BODY>
    </HTML>
 </xsl:template>
---
When the node 'DISPLAY' is encountered, you want to receive the 
following
result:
   <TR>
    <TH> Column1 </TH>
    <TH> Column2 </TH>
    <TH> Column3 </TH>
    <TH> Column4 </TH>
    <TH> Column5 </TH>
    <TH> Column6 </TH>
   </TR>
---
So you can write the following match for the '<display>' node:
 <xsl:template
   match="DISPLAY">
   <TR>
    <TH>
     <xsl:value-of select="."/>
    </TH>
   </TR>
 </xsl:template>
---
Putting this all together, and adding the necessary header information,
you get:
---
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<!-- library: (filenamemacro=titles.xsl) [kn, ri, fr, 21-09-2001 
18:09:17] -->
 <xsl:template
   match="/"
 >
   <xsl:apply-templates/>
 </xsl:template>
 <xsl:template
   match="TITLES">
    <HTML>
     <!-- (filenamemacro=titles.htm) -->
     <HEAD>
      <TITLE>
        Titles table
      </TITLE>
     </HEAD>
     <BODY
       BGCOLOR="white"
     >
      <TABLE
      >
       <CAPTION
         ALIGN="top"
       >
          Titles table
       </CAPTION>
        <TR>
         <xsl:apply-templates/>
        </TR>
      </TABLE>
     </BODY>
    </HTML>
 </xsl:template>
 <xsl:template
   match="DISPLAY">
    <TH>
     <xsl:value-of select="."/>
    </TH>
 </xsl:template>
</xsl:stylesheet>
---
which gives the result in your browser:
                        Titles table
   +----+------+-------+-------+---------+--------+---------+
   |Num | Time | Stamp | Agent | Channel | Reason | Comments|
   +----+------+-------+-------+---------+--------+---------+
---
  2.3.1 Save this file as 'titles.xsl'
---
3. Load the XML file in your browser
In the URL of your browser, type the path of where you have stored your
files, e.g. if you stored this 3 files in the 'c:\temp\' directory,
you type in the URL field of your browser the following text:
 c:\temp\titles.xml
---
4. Check the HTML result
Debugging and adapting your results:
Using e.g. XMLSpy, you can see the HTML output source code generated
(if you should look at the source code generated in say your Microsoft
Internet browser v5.0 or higher, you will see only the original XML
code instead)
---
5. Get the data from the primary database files (with the
   filenames received by reading the value of the 'ID' attribute)
to be continued...
---
Internet: see also:
http://www.faqts.com/knowledge_base/view.phtml/aid/7882/fid/671
--- Knud van Eeden - 21 September 2001 - 21:22 -----------------------
----------------------------------------------------------------------
http://www.roo7e.com
http://www.roo7e.com
http://www.al33ab.com
http://ksacam.com
http://chat.ksacam.com
http://ksacam.info
http://oo2o.com
http://s4cam.com
http://saudi4cam.com				
http://voice.ksacam.com
http://سعودي-كام.oo2o.com
http://سعوديكام.com
http://xn--mgbply5cnrr.com
http://www.3rabstarz.com/vb
http://www.3rabstarz.com/vb
http://www.3rabstarz.com/
http://www.3rabstarz.com/vb
http://www.3rabstarz.com/
http://www.dir.3rabstarz.com/
http://www.up.3rabstarz.com
http://www.3rabstarz.com/vb/forumdisplay.php?f=5
http://www.3rabstarz.com/vb/forumdisplay.php?f=116
http://www.3rabstarz.com/vb/forumdisplay.php?f=66
http://www.3rabstarz.com/vb/forumdisplay.php?f=78
http://www.3rabstarz.com/vb/forumdisplay.php?f=147
http://www.3rabstarz.com/vb/forumdisplay.php?f=2
http://www.3rabstarz.com/vb/forumdisplay.php?f=31
http://www.3rabstarz.com/vb/forumdisplay.php?f=136
http://www.3rabstarz.com/vb/forumdisplay.php?f=34
http://www.3rabstarz.com/vb/forumdisplay.php?f=89
http://www.3rabstarz.com/vb/forumdisplay.php?f=26
http://www.3rabstarz.com/vb/forumdisplay.php?f=72
http://www.3rabstarz.com/vb/forumdisplay.php?f=73
http://www.3rabstarz.com/vb/forumdisplay.php?f=149
http://www.3rabstarz.com/vb/forumdisplay.php?f=150
http://www.3rabstarz.com/vb/forumdisplay.php?f=151
http://www.3rabstarz.com/vb/forumdisplay.php?f=152
http://www.3rabstarz.com/vb/forumdisplay.php?f=67
http://www.3rabstarz.com/vb/forumdisplay.php?f=3
http://www.3rabstarz.com/vb/forumdisplay.php?f=37
http://www.3rabstarz.com/vb/forumdisplay.php?f=115
http://www.3rabstarz.com/vb/forumdisplay.php?f=76
http://www.3rabstarz.com/vb/forumdisplay.php?f=77
http://www.3rabstarz.com/vb/forumdisplay.php?f=36
http://www.3rabstarz.com/vb/forumdisplay.php?f=153
http://www.3rabstarz.com/vb/forumdisplay.php?f=122
http://www.3rabstarz.com/vb/forumdisplay.php?f=118
http://www.3rabstarz.com/vb/forumdisplay.php?f=119
http://www.3rabstarz.com/vb/forumdisplay.php?f=120
http://www.3rabstarz.com/vb/forumdisplay.php?f=121
http://www.3rabstarz.com/vb/forumdisplay.php?f=35
http://www.3rabstarz.com/vb/forumdisplay.php?f=65
http://www.3rabstarz.com/vb/forumdisplay.php?f=7
http://www.3rabstarz.com/vb/forumdisplay.php?f=9
http://www.3rabstarz.com/vb/forumdisplay.php?f=11
http://www.3rabstarz.com/vb/forumdisplay.php?f=142
http://www.3rabstarz.com/vb/forumdisplay.php?f=143
http://www.3rabstarz.com/vb/forumdisplay.php?f=146
http://www.3rabstarz.com/vb/forumdisplay.php?f=140
http://www.3rabstarz.com/vb/forumdisplay.php?f=137
http://www.3rabstarz.com/vb/forumdisplay.php?f=114
http://www.3rabstarz.com/vb/forumdisplay.php?f=117
http://www.3rabstarz.com/vb/forumdisplay.php?f=113
http://www.3rabstarz.com/vb/forumdisplay.php?f=51
http://www.3rabstarz.com/vb/forumdisplay.php?f=84
http://www.3rabstarz.com/vb/forumdisplay.php?f=138
http://www.3rabstarz.com/vb/forumdisplay.php?f=139
http://www.3rabstarz.com/vb/forumdisplay.php?f=15
http://www.3rabstarz.com/vb/forumdisplay.php?f=130
http://www.3rabstarz.com/vb/forumdisplay.php?f=97
http://www.3rabstarz.com/vb/forumdisplay.php?f=102
http://www.3rabstarz.com/vb/forumdisplay.php?f=101
http://www.3rabstarz.com/vb/forumdisplay.php?f=104
http://www.3rabstarz.com/vb/forumdisplay.php?f=131
http://www.3rabstarz.com/vb/forumdisplay.php?f=103
http://www.3rabstarz.com/vb/forumdisplay.php?f=99
http://www.3rabstarz.com/vb/forumdisplay.php?f=59
http://www.3rabstarz.com/vb/forumdisplay.php?f=60
http://www.3rabstarz.com/vb/forumdisplay.php?f=39
http://www.3rabstarz.com/vb/forumdisplay.php?f=40
http://www.3rabstarz.com/vb/forumdisplay.php?f=42
http://www.3rabstarz.com/vb/forumdisplay.php?f=4
http://www.3rabstarz.com/vb/forumdisplay.php?f=1
http://www.3rabstarz.com/vb/forumdisplay.php?f=88
http://www.3rabstarz.com/vb/forumdisplay.php?f=148
http://www.3rabstarz.com/vb/forumdisplay.php?f=62
http://www.3rabstarz.com/vb/forumdisplay.php?f=63
http://www.3rabstarz.com/vb/forumdisplay.php?f=64
http://www.3rabstarz.com/vb/forumdisplay.php?f=6
http://www.3rabstarz.com/vb/forumdisplay.php?f=12
http://www.3rabstarz.com/vb/forumdisplay.php?f=96
http://www.3rabstarz.com/vb/forumdisplay.php?f=58
http://www.3rabstarz.com/vb/forumdisplay.php?f=38