theguy
theguy

Reputation: 11

XSLT Bold not working

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet   
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:fo="http://www.w3.org/1999/XSL/Format" 
type="text/xsl" href="helpxslt.xsl" ?>

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="helpschema.xsd" >


    <line>
   This is a paragraph <b> of text</b> I only want some of it bold.
</line>

So this is the XML

    <xsl:for-each select="page/line">
        <p class="bodytext">
            <xsl:value-of select="."/>
            <xsl:call-template name="Newline"/>
        </p>
    </xsl:for-each>
    <xsl:for-each select="page/line/b">
        <b>
            <xsl:value-of select="."/>          
        </b>
    </xsl:for-each>
</xsl:template>

this is the XLST.

Why won't it work? It just pastes the text twice. :(

Upvotes: 1

Views: 252

Answers (2)

Michael Kay
Michael Kay

Reputation: 163322

The xsl:value-of instruction extracts the raw text of what you select, discarding all the markup. You want xsl:copy-of.

More specifically, try to learn to code this "the XSLT way" doing a rule-based recursive descent with xsl:apply-templates and template rules. This is a much more appropriate way of handling mixed content than using quasi-procedural constructs such as xsl:for-each and xsl:choose.

Upvotes: 1

Lumi
Lumi

Reputation: 15264

<xsl:for-each select="page/line">
    <p class="bodytext">
        <xsl:copy-of select="node()"/>
        <xsl:call-template name="Newline"/>
    </p>
</xsl:for-each>

Upvotes: 1

Related Questions