How to generate bold and italic text using XSLT

Here should go questions about transforming XML with XSLT and FOP.
slaterino
Posts: 11

How to generate bold and italic text using XSLT

Wed Feb 03, 2010 10:47 pm

Hi,
I am having some problems generating bold and italic text. I have tried a few different methods, and found quite a few suggestions on the Net, but nothing seems to work. A sample of my XML for me at the moment is like this:

Code: Select all

 <para><emphasis role="bold">Taxi:</emphasis> Good news! Montevideo’s taxi drivers are, in our opinion, honest and invariably helpful. Taxis are hailed in the street or picked up at a taxi rank. They use a meter that clocks up a number of units (fichas) which have to be converted into the fare you pay by consulting a <emphasis role="italic">fare chart</emphasis>, which is displayed in the back of each cab.</para>


This unfortunately has a major flaw as the XSL I am using makes the whole paragraph bold even if there are only a couple of words that are within the bold tags. I know there is a way to do this by having <text></text><b></b><text></text> and so on but this is a ridiculous amount of extra work. Does anyone know how I can get this to work better? The current XSL I am using is:

Code: Select all

    <xsl:template match="para">
        <p>
            <xsl:choose>           
            <xsl:when test='emphasis[@role="bold"]'>
                <xsl:element name="strong">
                    <xsl:value-of select="."/>
                </xsl:element>   
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="."/>
            </xsl:otherwise>       
            </xsl:choose>
        </p>
    </xsl:template>

Return to “XSLT and FOP”

Who is online

Users browsing this forum: No registered users and 2 guests