This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: xsl script
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: RE: [xsl] xsl script
- From: "Chris Bayes" <Chris at Bayes dot co dot uk>
- Date: Thu, 12 Jul 2001 10:47:17 +0100
- Reply-To: xsl-list at lists dot mulberrytech dot com
Paul,
This isn't really an xslt problem. You are getting the error because
sortField is null and not an object. You do this to find your sort element
sortField =
document.XSLDocument.selectSingleNode("//xsl:sort[@select='p:project_number'
]");
and you do not have a sort element with a select that equals
p:project_number so selectSingleNode returns null. When you try and use it
it gives that error.
I would change the way you do this to pass a param to the stylesheet. Have a
look on my site in the tutorials section to find out how to do this.
Ciao Chris
XML/XSL Portal
http://www.bayes.co.uk/xml
>-----Original Message-----
>From: owner-xsl-list@lists.mulberrytech.com
>[mailto:owner-xsl-list@lists.mulberrytech.com]On Behalf Of
>Paul_B_Grimes@dot.ca.gov
>Sent: 12 July 2001 00:29
>To: xsl-list@lists.mulberrytech.com
>Subject: [xsl] xsl script
>
>
>I am fairly stuck with the following code. I keep getting an error message
>stating "sortField is null or is not an object" If anyone can help me
>point out the problem with my code, it would be greatly appreciated. (the
>code is shown below). This stylesheet is linked to an xml document with
>the following format.
>
>
><current_projects xmlns="x-schema:sortProjects-schema.xml">
> <contents>Project Listing</contents>
> <date_span>2000 - 2001</date_span>
> <project>
> <project_title>PenMap Demonstration</project_title>
> <project_number>6</project_number>
> <description>blah blah</description>
> <start_date>7-23-01</start_date>
> <completion_date>8-19-01</completion_date>
> <cost>8000</cost>
> <contact_name>Loren Turner</contact_name>
> <contact_number>(916) 227-7174</contact_number>
> <branch>Geotechnology Implemtation Program</branch>
> </project>
> <project>
> <project_title>Continuous GPS: Pilot Applications - Phase
>I</project_title>
> <project_number>2</project_number>
> <description>blah blah</description>
> <start_date>4-12-01</start_date>
> <completion_date>9-20-01</completion_date>
> <cost>110000</cost>
> <contact_name>Loren Turner</contact_name>
> <contact_number>(916) 227-7174</contact_number>
> <branch>Geotechnology Implementation Program</branch>
> </project>
>.
>.
>.
>
>
>Thank You
>Paul Grimes
>
><?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:blue; color:white}
> h1 {font:bold 14pt Verdana; width:100%; margin-top:1em}
> .row {font:8pt Verdana; border-bottom:1px solid green}
> .header {font:bold 9pt Verdana; cursor:hand; padding:2px;
>border:2px outset gray}
> .up {background-color:lightsteelblue;}
> .down {background-color:whitesmoke;}
> </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_number']");
> ]]></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="120" 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">
> <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_date',
>'number')">Start Date</div></td>
> <td><div class="header" onClick="sort('completion_date',
>'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>
> </thead>
> <xsl:for-each select="p:project">
> <xsl:sort select="project_title"
>data-type="text"/>
> <tr>
> <xsl:for-each select="p:project_number">
> <xsl:if test=". > 20">
> <xsl:attribute name="class">up</xsl:attribute>
> </xsl:if>
> </xsl:for-each>
> <xsl:for-each select="start_date">
> <xsl:if test=". < 0">
> <xsl:attribute name="class">down</xsl:attribute>
> </xsl:if>
> </xsl:for-each>
> <xsl:for-each select="completion_date">
> <xsl:if test=". < 0">
> <xsl:attribute name="class">down</xsl:attribute>
> </xsl:if>
> </xsl:for-each>
> <td><div class="row"><xsl:value-of select
>="p:project_title"/></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>
> </tr>
> </xsl:for-each>
> </table>
> </xsl:template>
>
>
> <xsl:template match="p:cost">
> <xsl:value-of select="format-number(., '##0.00')"/>
> </xsl:template>
></xsl:stylesheet>
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list