Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 17th, 2010, 12:31 PM
Registered User
 
Join Date: Jan 2010
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Question Does my xsl look good to you?

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:
Code:
<?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=0A...p6dGpkbg&hl=en

The link for the html output is
https://docs.google.com/Doc?docid=0A...QzdzMybg&hl=en

Thanks a trillion!
 
Old February 18th, 2010, 01:11 PM
Registered User
 
Join Date: Jan 2010
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default

The link in the html output should be the first fine:

Abstract Materials Results Discussion

Each of the above words links to the section of that page. In my xml, I tried
Code:
    <xsl:template match="//body/sec">
      <center>
        <font color="blue">
          <br/>
          <xsl:if test="title">
            <xsl:if test=".='MATERIALS AND METHODS'">
              <a name="mat"><xsl:apply-templates select="title"/> </a>
            </xsl:if>
            <xsl:if test=".='RESULTS'">
              <a name="res"><xsl:apply-templates select="title"/> </a>
            </xsl:if>
            <xsl:if test=".='DISCUSSION'">
              <a name="dis"><xsl:apply-templates select="title"/> </a>
            </xsl:if>
            <a name="res"><xsl:apply-templates select="title"/> </a>
          </xsl:if>
        </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>
But it didn't work. The '<a name="res"<xsl:applytemplates select="title"/></a>'
gave name "res" to every section. But if I take that line out, all the section titles are gone.
Thanks!!





Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl:function pass param to attribute of xsl:instruction bonekrusher XSLT 4 March 31st, 2009 09:06 AM
xsl:param and xsl:apply-templates' "select" newbieboobers XSLT 1 March 25th, 2008 07:23 PM
Pass link values as xsl:parameter to php5 then xsl pauljr8 XSLT 1 July 2nd, 2007 10:32 PM
A good XSL-FO forum? lthompso XSLT 3 March 22nd, 2006 06:51 AM
XSL Transform with xsl string NOT xsl file skin XSLT 0 June 16th, 2003 07:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.