Hello,
I am trying to process the first node in a sequence of like nodes differently than the others (somewhat). Here is a sample and I'll explain.
Source doc:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<body>
<heading>heading text</heading>
<bodytext>bodytext1</bodytext>
<bodytext>bodytext2</bodytext>
<bodytext>bodytext3</bodytext>
<bodytext>bodytext4</bodytext>
</body>
</root>
and my attempt at the stylesheet
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="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="root">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="heading">
<Para FirstLineIndent="7">
<xsl:value-of select="."/>
<xsl:apply-templates select="bodytext[1]"/>
</Para>
</xsl:template>
<xsl:template match="bodytext">
<xsl:choose>
<xsl:when test="../bodytext[position()=1]">
<HardSp/><HardSp/>
<xsl:apply-templates select="text()"/>
</xsl:when>
<xsl:otherwise>
<Para FirstLineIndent="7">
<xsl:apply-templates/>
</Para>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
What I am trying to do is bring the first line of bodytext up into the same paragraph with the heading. All other bodytext elements should be in their own paragraphs. Such as:
<Para FirstLineIndent=7>heading text bodytext1</Para>
<Para FirstLineIndent=7>bodytext2</Para>
<Para FirstLineIndent=7>bodytext3</Para>
<Para FirstLineIndent=7>bodytext4</Para>
I have tried using the position() function to check if the bodytext element is the first in the series, but cannot seem to get this to work. Some of the errors I see are for un-matched pairs of Para tags, etc.
Are there any suggestions as to how to accomplish this?
Thanks in advance,
Dan