This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Is this a legal XPath Expression?
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: RE: [xsl] Is this a legal XPath Expression?
- From: "Phil Gooch" <phil dot gooch at csw dot co dot uk>
- Date: Thu, 15 Mar 2001 11:56:32 -0000
- Reply-To: xsl-list at lists dot mulberrytech dot com
Thanks for that Mike.
Basically what I am doing is trying to find unique occurrences of the
contents of cells in column 15 of an HTML table, e.g
<td>Working conditions</td>
...
<td>Living conditions</td>
...
<td>Working conditions</td>
...
<td>Industrial relations</td>
...
<td>Living conditions</td>
...
, then, for each of these, pick out unique occurrences of the contents of
cells in column 28, and for each of those, pick out the contents of cell 3.
Looks like a job for <saxon:group>, but I couldn't figure out how to do it,
so my code looks like this: (it works, but its v. inefficient!)
<xsl:template match="TD[15]">
<!-- subject is in cell 15 -->
<xsl:variable name="subject"
select="node()[not(.=preceding::TR/TD[15]/node())]"/>
<xsl:if test="$subject !=''">
<xsl:variable name="link" select="generate-id()"/>
<tr>
<td>
<a href="{$link}.html"><xsl:value-of select="$subject"/></a>
</td>
</tr>
<!-- for each subject, output the project title to a sep. file-->
<saxon:output file="{concat($link, '.html')}">
<html><head></head>
<body><table>
<xsl:for-each select="//TR">
<xsl:apply-templates select="TD[28]">
<xsl:with-param name="subj" select="$subject"/>
</xsl:apply-templates>
</xsl:for-each>
</table>
</body>
</html>
</saxon:output>
</xsl:if>
</xsl:template>
<!-- project title is in cell 28 -->
<xsl:template match="TD[28]">
<xsl:param name="subj"/>
<xsl:if test="../TD[15]/node()=$subj">
<xsl:variable name="projecttitle"
select="node()[not(.=preceding::TR/TD[28]/node())]"/>
<xsl:if test="$projecttitle!=''">
<xsl:variable name="link" select="generate-id()"/>
<tr>
<td>
<a href="{$link}.html"><xsl:value-of select="$projecttitle"/></a>
</td>
</tr>
<!-- for each project, output the filename to a sep. file-->
<saxon:output file="{concat($link, '.html')}">
<html><head></head>
<body><table>
<xsl:for-each select="//TR">
<xsl:apply-templates select="TD[3]">
<xsl:with-param name="proj" select="$projecttitle"/>
</xsl:apply-templates>
</xsl:for-each>
</table>
</body>
</html>
</saxon:output>
</xsl:if>
</xsl:if>
</xsl:template>
<xsl:template match="TD[3]">
<xsl:param name="proj"/>
<xsl:if test="../TD[28]/node()=$proj">
<xsl:variable name="fn" select="."/>
<tr>
<td>
<a href="{$fn}">Download <xsl:value-of select="$fn"/></a>
</td>
</tr>
</xsl:if>
</xsl:template>
Phil
> -----Original Message-----
> From: owner-xsl-list@lists.mulberrytech.com
> [mailto:owner-xsl-list@lists.mulberrytech.com]On Behalf Of Michael Kay
> Sent: Wednesday, March 14, 2001 9:31 PM
> To: xsl-list@lists.mulberrytech.com
> Subject: RE: [xsl] Is this a legal XPath Expression?
>
>
> > Subject: [xsl] Is this a legal XPath Expression?
>
> > select=".[not(.=preceding::TR/TD[15]/node())]"
> >
>
> No, it isn't legal. "." is an AbbreviatedStep, as such it is a Step, and a
> Step cannot be followed by a Predicate.
>
> Write select="self::node()[not(.=preceding::TR/TD[15]/node())]"
>
> Or in the context where you are using it,
>
> <xsl:template match="TR/TD[15]">
> <xsl:variable name="subject"
> select="not(.=preceding::TR/TD[15]/node())"/>
> <xsl:if test="$subject">
> <tr>
> <td>
> <a href="{.}.html"><xsl:value-of
> select="."/></a>
> </td>
> </tr>
> </xsl:if>
> </xsl:template>
>
> I'm suspicious about that TR[15]/node() as well: what if it's a comment?
>
> Mike Kay
> Software AG
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
>
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list