
July 22nd, 2004, 03:55 AM
|
|
Registered User
|
|
Join Date: Sep 2001
Posts: 16
Time spent in forums: 13 m 56 sec
Reputation Power: 0
|
|
|
XSL/XSLT one random node display, need help
Hello,
I am trying to accomplish to get from XML via XSL display of one random node, in my case "item" node.
I have tried with below code, but won't work.
I need it from XSL or XSLT ... thx in advance for help.
Code:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" version="4.0" encoding="iso-8859-1" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="channel">
<xsl:apply-templates select="item[position()<=1]"/>
<xsl:apply-templates select="math:random(count(item))"/>
<xsl:copy-of select="item[position() = current()]"/>
</xsl:template>
<xsl:template match="image">
<a target="_blank">
<xsl:attribute name="href">
<xsl:value-of select="link"/>
</xsl:attribute>
<img>
<xsl:attribute name="src">
<xsl:value-of select="url"/>
</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="title"/>
</xsl:attribute>
<xsl:attribute name="width">
<xsl:value-of select="width"/>
</xsl:attribute>
<xsl:attribute name="height">
<xsl:value-of select="height"/>
</xsl:attribute>
</img>
</a>
</xsl:template>
<xsl:template match="item">
<strong>
<a target="_blank">
<xsl:attribute name="href">
<xsl:value-of select="link"/>
</xsl:attribute>
<xsl:value-of select="title" />
</a>
</strong>
<xsl:apply-templates select="description"/>
</xsl:template>
<xsl:template match="description">
<br>
<xsl:value-of select="." disable-output-escaping="yes"/>
</br>
<br></br>
<br></br>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
|