开发者

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="."/>
   开发者_StackOverflow         <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. :(


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜