Hi,
I have an XML document made up of <P></P> and <L></L> (as well as other things).
My XSLT renders (as you might of guessed) the <P>'s as HTML paragraphs and <L>'s as lists.
Currently it renders all of the paragraphs first and then the lists.
I think, I need a way to figure out what element (don't know if that's the right word) I am in, then apply the template as needed.
i.e.
Code:
if (current_element == P)
{
<p>current_element.contents</p>
}
else if (current_element == L)
{[list]
<li>current_element.contents</li>
</ul>
}
I have tried using current() and every combination of * . // etc etc I can think of, but to no avail.
Any help, would be greatly appreciated!
-thanks
Alex.
this is the XSLT I currently have (below), I tried to post my XML as well, but its too big and timed out :( ...
Code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xmlt1-transitional.dtd" doctype-public="-//W3C/DTD XHTML 1.0 Transitional//EN" indent="yes"/>
<xsl:template match="/">
<html>
<head>
<title>Asthma XSL test</title>
<link href="../styles/global.css" media="screen" type="text/css" rel="stylesheet"/>
</head>
<body>
<a name="top"/>
<h1>
<img height="45" alt="AstraZenenca" src="../images/azlogo.gif" width="175"/>
</h1>
<div id="container">
<h2>
<xsl:value-of select="/TaggedPDF-doc/P[1]"/>
<br/>
<xsl:value-of select="/TaggedPDF-doc/H1[2]/text()[1]"/>
</h2>
<div id="accessibilityNotice">
<p>AstraZeneca has delivered this text only version of the course to serve those users who have difficulty accessing the interactive version.</p>
<p>You can access it here:
<a href="#">Full Interactive Version</a>
</p>
</div>
<ol>
<xsl:for-each select="//H2 | //P[translate(substring(.,1,1), '0123456789', '9999999999') = '9' and translate(substring(.,3,1), '0123456789', '9999999999') = '.'] ">
<li value="0">
<a href="#{generate-id()}">
<xsl:value-of select="."/>
</a>
</li>
</xsl:for-each>
</ol>
<p>
<strong>
<xsl:value-of select="substring(TaggedPDF-doc/Part/P,1,17)"/>
</strong>
<xsl:value-of select="substring(TaggedPDF-doc/Part/P,18,100)"/>
</p>
<xsl:apply-templates select="TaggedPDF-doc/Part/Sect"/>
</div>
</body>
</html>
</xsl:template>
<xsl:template match="Sect">
<xsl:apply-templates select="H2"/>
<!-- <xsl:for-each select="//P | //L">
<xsl:choose>
<xsl:when test="*[current()=P]"> -->
<xsl:apply-templates select="P"/>
<!-- </xsl:when>
<xsl:when test="*[current()=L]"> -->
<xsl:apply-templates select="L"/>
<!-- </xsl:when>
</xsl:choose>
</xsl:for-each>
-->
<xsl:if test="*[position()=last()]">
<p class="backtotop">
<a href="#top">Back to Top</a>
</p>
</xsl:if>
</xsl:template>
<xsl:template match="H2">
<a name="{generate-id()}"></a>
<h3>
<xsl:value-of select="."/>
</h3>
</xsl:template>
<xsl:template match="P">
<xsl:choose>
<xsl:when test="text()[starts-with(.,'Introduction')]">
<h4>
<xsl:value-of select="."/>
</h4>
</xsl:when>
<xsl:when test="text()[starts-with(.,'Transcript')]">
<h4>
<xsl:value-of select="."/>
</h4>
</xsl:when>
<xsl:when test="text()[starts-with(.,'Table Text')]">
<p>
<strong>
<xsl:value-of select="substring(.,1,10)"/>
</strong>
<xsl:value-of select="substring(.,11,500000000)"/>
</p>
</xsl:when>
<!--Caters for titles that are wrongly in P tags in the XML, by seeing if they start with a 2 digit number and a "."
and creates an anchort for them-->
<xsl:when test="translate(substring(.,1,1), '0123456789', '9999999999') = '9' and translate(substring(.,3,1), '0123456789', '9999999999') = '.'">
<a name="{generate-id()}"></a>
<h3>
<xsl:value-of select="."/>
</h3>
</xsl:when>
<xsl:when test="text()[starts-with(.,'Rollover Text')]">
<p>
<strong>
<xsl:value-of select="substring(.,1,14)"/>
</strong>
<xsl:value-of select="substring(.,15,500000000)"/>
</p>
</xsl:when>
<!--
<xsl:when test="//* = preceding-sibling::*[text()[starts-with(.,'Rollover Text:')]]">
<strong><xsl:value-of select="."/></strong>
</xsl:when>-->
<xsl:otherwise>
<p>
<xsl:value-of select="."/>
</p>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="L">
[list]
<xsl:for-each select="LI">
<li>
<xsl:value-of select="LI_Title"/>
</li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>