problem using the xsl method for-each

Posted by joe on Stack Overflow See other posts from Stack Overflow or by joe
Published on 2009-11-30T17:11:15Z Indexed on 2010/05/11 4:04 UTC
Read the original article Hit count: 185

Filed under:
|
|

Using XSL I am trying to turn this XML:

<book><title>This is a <b>great</b> book</title></book>

into this XML:

<book>This is a <bold>great</bold> book</book>

using this xsl:

<xsl:for-each select="book/title/*">
<xsl:choose>
    <xsl:when test="name() = 'b'">
    	<bold>
    		<xsl:value-of select="text()"/>
    	</bold>
    </xsl:when>
    <xsl:otherwise>
    	<xsl:value-of select="text()"/>
    </xsl:otherwise>
</xsl:choose>
</xsl:for-each>

but my output is looking like this:

<book><bold>great</bold></bold>

Can anyone explain why the root text of <title> is getting lost? I believe my for-each select statement may need to be modified but I can't figure out what is should be.

Keep in mind that I cannot use an <xsl:template match> because of the complexity of my style sheet.

Thanks!

© Stack Overflow or respective owner

Related posts about xslt

Related posts about Xml