Re: [xsl] hyperlink

Subject: Re: [xsl] hyperlink
From: Paul_B_Grimes@xxxxxxxxxx
Date: Thu, 19 Jul 2001 12:02:36 -0700
Hi Jeni,

     Unfortunately, I was not able to get it to work using 'concat('proj',
count(preceding-sibling::project))' either.  Although, this in no way
implies that it isn't the solution, as I have only been at this xml/xsl
stuff for about a month.  Does the generate-id() function need to be
defined in the schema?
I'll go ahead and include the source files for this app. I've highlighted
the changes in red.  If you could find the time to take a peek at them,
that would be wonderful. Sorry about the length of this message.

Here are the files:

XML:
<?xml:stylesheet type="text/xsl" href="sortProjects.xsl"?>
<current_projects xmlns="x-schema:sortProjects-schema.xml">
     <contents>Project Listing</contents>
     <date_span dt="dateTime">2000 - 2001</date_span>
     <project>
                  <project_title>PenMap Demonstration</project_title>
                  <project_number dt="fixed.14.4">6</project_number>
                  <description>This technology transfer project will expose
the latest field data ...
                  </description>
        <start_date dt="fixed.14.4">7-23-01</start_date>
                   <start_convert dt="fixed.14.4">20010723</start_convert>
        <completion_date dt="fixed.14.4">8-19-01</completion_date>
                   <completion_convert dt
="fixed.14.4">20010819</completion_convert>
        <cost dt="fixed.14.4">8000</cost>
        <contact_name>Loren Turner</contact_name>
        <contact_number dt="fixed.14.4">(916) 227-7174</contact_number>
        <branch>Geotechnology Implemtation Program</branch>
     </project>
     <project>
        <project_title>Continuous GPS: Pilot Applications - Phase
I</project_title>
                   <project_number dt="fixed.14.4">2</project_number>
        <description>This project will focus on ...
                   </description>
        <start_date dt="fixed.14.4">4-12-01</start_date>
                   <start_convert dt="fixed.14.4">20010412</start_convert>
        <completion_date dt="fixed.14.4">9-20-01</completion_date>
                   <completion_convert dt
="fixed.14.4">20010920</completion_convert>
        <cost dt="fixed.14.4">110000</cost>
        <contact_name>Loren Turner</contact_name>
        <contact_number dt="fixed.14.4">(916) 227-7174</contact_number>
        <branch>Geotechnology Implementation Program</branch>
     </project>
     <project>
        <project_title>Continuous GPS: Pilot Applications - Phase II
                   </project_title>
        <project_number dt="fixed.14.4">3</project_number>
        <description>This project will develop, and test ...</description>
        <start_date dt="fixed.14.4">2-17-01</start_date>
                   <start_convert dt="fixed.14.4">20010217</start_convert>
        <completion_date dt="fixed.14.4">9-22-01</completion_date>
                   <completion_convert dt
="fixed.14.4">20010922</completion_convert>
        <cost dt="fixed.14.4">85000</cost>
        <contact_name>Loren Turner</contact_name>
        <contact_number dt="fixed.14.4">(916) 227-7174</contact_number>
        <branch>Geotechnology Implentation Progam</branch>
     </project>
.
.
.
</current_projects>

XSL:
<?xml version="1.0"?>
<xsl:stylesheet
     xmlns:p="x-schema:sortProjects-schema.xml"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
     <xsl:output method="html"/>
  <xsl:template match="/">
     <html>
      <head>
       <style>
         body {margin:0}
         .bg {font:8pt Verdana; background-color:steelblue; color:white}
         h1 {font:bold 14pt Verdana; width:100%; margin-top:1em}
         .row {font:8pt Verdana;}
         .header {font:bold 9pt Verdana; cursor:hand; padding:2px;
border:2px outset gray}
         .up {background-color:lightsteelblue;}
         .down {background-color:steelblue;}
       </style>
      </head>
      <script><xsl:comment><![CDATA[
              var stylesheet = null;
                    var source = null;
                          var sortField =null;
          function sort(field, datatype)
           {
            sortField.setAttribute("select", "p:" + field);
            sortField.setAttribute("data-type", datatype);
            listing.innerHTML =
source.documentElement.transformNode(stylesheet);
           }
       ]]></xsl:comment></script>
      <script for="window" event="onload"><xsl:comment><![CDATA[
        stylesheet = document.XSLDocument;
        source = document.XMLDocument;
        sortField = document.XSLDocument.selectSingleNode("//xsl:sort
[@select='p:project_title']");
       ]]></xsl:comment></script>

       <body>
         <table width="100%" cellspacing="0">
           <tr>
             <td class="bg"/>
             <td class="bg">
               <h1><xsl:value-of select="p:current_projects/p:contents"/>
                 for <xsl:apply-templates select
="p:current_projects/p:date_span"/></h1>
             </td>
           </tr>
           <tr>
             <td class="bg" width="70" valign="top">
               <p>Click on the column headers to sort by that field.</p>
             </td>
             <td class="bg" valign="top">
               <div id="listing"><xsl:apply-templates select
="p:current_projects"/></div>
             </td>
           </tr>
          </table>
        </body>
      </html>
     </xsl:template>
     <xsl:template match="p:current_projects">
         <table style="background-color:whitesmoke" border="1" rules="rows"
frame="below" bordercolor="steelblue" cellpadding="2" id="data">
           <thead>
             <td><div class="header" onClick="sort('project_title',
'text')">Project <br/>Title<br/></div></td>
             <td><div class="header" onClick="sort('project_number',
'number')">Project Number</div></td>
             <td><div class="header" onClick="sort('start_convert',
'number')">Start Date</div></td>
             <td><div class="header" onClick="sort('completion_convert',
'number')">Completion Date</div>
             </td>
             <td><div class="header" onClick="sort('cost',
'number')">Project Cost</div></td>
             <td><div class="header" onClick="sort('contact_name',
'text')">Contact Name</div></td>
             <td><div class="header" onClick="sort('contact_number',
'number')">Contact Number</div></td>
             <td><div class="header" onClick="sort('branch',
'text')">Branch<br /><br /></div></td>
           </thead>
           <xsl:for-each select="p:project">
                                     <xsl:sort select="p:project_title"
data-type="text"/>
             <tr>
              <td><div class="row"><a href="#{generate-id()}">
                                      <xsl:value-of select
="p:project_title"/></a></div></td>
              <td><div class="row" style
="text-align:right"><xsl:apply-templates select
="p:project_number"/></div></td>
              <td><div class="row" style
="text-align:right"><xsl:apply-templates select="p:start_date"/></div></td>
              <td><div class="row" style
="text-align:right"><xsl:apply-templates select
="p:completion_date"/></div></td>
              <td><div class="row" style="text-align:right">
$<xsl:apply-templates select="p:cost"/></div></td>
              <td><div class="row"><xsl:value-of select
="p:contact_name"/></div></td>
              <td><div class="row" style
="text-align:right"><xsl:apply-templates select
="p:contact_number"/></div></td>
              <td><div class="row"><xsl:value-of select
="p:branch"/></div></td>
          </tr>
          <tr>

<td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
          </tr>
         </xsl:for-each>
        </table>
       </xsl:template>
            <xsl:template match="p:project">
             <h2>
              <a name="{generate-id()}" id="{generate-id()}">
               <xsl:value-of select="p:project_title" />
              </a>
             </h2>
            <xsl:apply-templates select="p:description" />
           </xsl:template>
      <xsl:template match="p:cost">
         <xsl:value-of select="format-number(., '##0.00')"/>
      </xsl:template>
</xsl:stylesheet>


Schema:
<?xml version="1.0"?>
<Schema xmlns="urn:schemas-microsoft-com:xml-data"
        xmlns:dt="urn:schemas-microsoft-com:datatypes">


<ElementType name="date_span" dt:type="dateTime"/>
<ElementType name="contents"/>

<ElementType name="project_title"/>
<ElementType name="project_number" dt:type="fixed.14.4"/>
<ElementType name="start_date" dt:type="fixed.14.4"/>
<ElementType name="start_convert" dt:type="fixed.14.4"/>
<ElementType name="completion_date" dt:type="fixed.14.4"/>
<ElementType name="completion_convert" dt:type="fixed.14.4"/>
<ElementType name="cost" dt:type="fixed.14.4"/>
<ElementType name="contact_name"/>
<ElementType name="contact_number" dt:type="fixed.14.4"/>

<ElementType name="current_projects" content="eltOnly">
   <group minOccurs="0" maxOccurs="1">
     <element type="contents"/>
   </group>
   <group minOccurs="0" maxOccurs="1">
     <element type="date_span" />
   </group>
   <group minOccurs="1" maxOccurs="1">
     <element type="project"/>
   </group>
</ElementType>

<ElementType name="project" content="eltOnly">
   <element type="project_title" />
   <element type="project_number" />
   <element type="start_date" />
   <element type="start_convert" />
   <element type="completion_date" />
   <element type="completion_convert" />
   <element type="cost" />
   <element type="contact_name" />
   <element type="contact_number" />
</ElementType>

</Schema>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread