Re: AW: [xsl] Special processing for the first process of an element

Subject: Re: AW: [xsl] Special processing for the first process of an element
From: Peter Hickman <peter@xxxxxxxxxxxxx>
Date: Wed, 10 Nov 2004 15:51:36 +0000
Thanks for the ideas, this is what I have got and it appears to work for the various test cases I have put together.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
<xsl:output method="html" />


   <xsl:template match="/">
       <xsl:apply-templates select="*|text()" />
   </xsl:template>

   <xsl:template match="p">
       <p><xsl:apply-templates select="*|text()" /></p>
   </xsl:template>

   <xsl:template match="document">
       <document><xsl:apply-templates select="*|text()" /></document>
   </xsl:template>

<xsl:template match="result">
<xsl:choose>
<xsl:when test="preceding::result">
<result class="rest"><xsl:apply-templates select="*|text()" /></result>
</xsl:when>
<xsl:otherwise>
<result class="first"><xsl:apply-templates select="*|text()" /></result>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>


For the test data:

<document>
 <p>
   <p>
     <p>
       <result>First</result>
     </p>
   </p>
   <p>
     <result>Second</result>
   </p>
 </p>
</document>

and a slightly harder document

<document>
   <p>tom
       <p>dick
           <p>harry
               <result>First</result>
           </p>
       </p>
   </p>
   <p>william
       <result>Second</result>
       <result>Third</result>
   </p>
</document>

Thanks again

Current Thread