Hi, I'm new to xslt. I need to write a xslt on medical journals.
I made it work. But I found if I need to add something later, it's hard to do. Right now, I'm trying to add links to different sections. I know I need to use test on element value. Though I found some sample codes about this, but it doesn't work with my xsl.
And I know there are many ways to write xsl, maybe I'm not doing it in the smart way. Thanks a lot!
Here is my xsl:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<body bgcolor="#FFFFFF">
<a href="#abs">Abstract</a>
<xsl:text> </xsl:text>
<a href="#mat">Materials</a>
<xsl:text> </xsl:text>
<a href="#res">Results</a>
<xsl:text> </xsl:text>
<a href="#dis">Discussion</a>
<xsl:apply-templates select="//title-group/article-title"/>
<xsl:apply-templates select="//contrib/name"/>
<br/>
<xsl:apply-templates select="//aff"/>
<xsl:apply-templates select="//corresp"/>
<xsl:apply-templates select="//abstract"/>
<xsl:apply-templates select="//kwd-group/kwd"/>
<xsl:apply-templates select="//body/sec"/>
<xsl:apply-templates select="//back/ack"/>
<xsl:apply-templates select="//back/ref-list"/>
</body>
</html>
</xsl:template>
<xsl:template match="//title-group/article-title">
<br/><h3><xsl:apply-templates/></h3>
</xsl:template>
<xsl:template match="//contrib/name">
<xsl:apply-templates select="given-names"/>
<xsl:text> </xsl:text>
<xsl:apply-templates select="surname"/>
<xsl:text>, </xsl:text>
</xsl:template>
<xsl:template match="//aff">
<br/>
<font color="grey">
<xsl:apply-templates select="child::text()"/>
</font>
</xsl:template>
<xsl:template match="//corresp">
<br/>
<font color="grey">
<xsl:apply-templates select="label"/>
<xsl:apply-templates select="child::text()"/>
<font color="blue"><xsl:apply-templates select="email"/></font>
</font>
</xsl:template>
<xsl:template match="//abstract">
<h4><center><a name="#abs">Abstract</a></center></h4>
<xsl:apply-templates/>
<br/><br/><b>Keywords: </b>
</xsl:template>
<xsl:template match="//kwd-group/kwd">
<xsl:apply-templates/>
<xsl:text>, </xsl:text>
</xsl:template>
<xsl:template match="//body/sec">
<center><font color="blue">
<br/><xsl:apply-templates select="title"/>
</font></center>
<br/>
<xsl:for-each select="p">
<xsl:apply-templates/>
<br/><br/>
</xsl:for-each>
<xsl:for-each select="sec">
<center><b>
<br/><xsl:apply-templates select="title"/>
</b></center>
<br/>
<xsl:apply-templates select="p"/>
<br/><br/>
</xsl:for-each>
<!-- <xsl:for-each select="descendant::p">
<xsl:apply-templates/>
<br/><br/>
</xsl:for-each> -->
</xsl:template>
<xsl:template match="//back/ack">
<center><font color="blue">
<br/><xsl:apply-templates select="title"/>
</font></center>
<br/>
<xsl:apply-templates select="p"/>
</xsl:template>
<xsl:template match="//back/ref-list">
<center><font color="blue">
<br/><xsl:apply-templates select="title"/>
</font></center>
<br/>
<xsl:for-each select="ref">
<xsl:apply-templates/>
<br/><br/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Sorry!. This is long. The link for the xml is
https://docs.google.com/Doc?docid=0ARrdEE8AtkWQZGdramdqZDZfMjJocGp6dGpkbg&hl=en
The link for the html output is
https://docs.google.com/Doc?docid=0ARrdEE8AtkWQZGdramdqZDZfMjNnZnQzdzMybg&hl=en
Thanks a trillion!