Re: [xsl] nested output

Subject: Re: [xsl] nested output
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 21 Dec 2004 16:12:08 GMT
> Here's the LaTeX transformed from the above:

?? the result you posted had no latex markup at all (and does have a
couple of strange characters (octal 226, decimal 150) just after each
page number, is that intended to be a dash of some sort?

> pp. 15476.


   <xsl:template match="xhtml:span" mode="output-latex">
     <xsl:variable name="content" select="."/>
     <xsl:for-each select="tokenize(@class, ' ')">
       <xsl:variable name="css-class" select="."/>
       <xsl:choose>
         <xsl:when test="$css-class='italic'">
           <xsl:text>\textit{</xsl:text>
           <xsl:value-of select="$content"/>
           <xsl:text>}</xsl:text>
         </xsl:when>
         <xsl:when test="$css-class='bold'">
           <xsl:text>\textbf{</xsl:text>
           <xsl:value-of select="$content"/>
           <xsl:text>}</xsl:text>
         </xsl:when>
         <xsl:otherwise>
           <xsl:apply-templates select="$content"/>
         </xsl:otherwise>
       </xsl:choose>
     </xsl:for-each>
   </xsl:template>


This will repeat the string-value of the content span once for each
token in the class attribute. If your span ever has any markup
that should be transformed you want apply-templates not
value-of, and you only want to do it once.

Also there's no need to do a for-each over tokenize(@class, ' ')
as string equality testing automatically will work over the entire
sequence.

something like

   <xsl:template match="xhtml:span" mode="output-latex">
     <xsl:variable name="c" select="tokenize(@class, ' +')">

         <xsl:if test="$c='italic'">\textit{</xsl:if>
         <xsl:if test="$c='bold'">\textbf{</xsl:if>

          <xsl:apply-templates/>

         <xsl:if test="$c='italic'">}</xsl:if>
         <xsl:if test=".='bold'">}</xsl:if>
 </xsl:template>


untested

David


________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread