[xsl] Walking through text with embedded tags

Subject: [xsl] Walking through text with embedded tags
From: "Bruce Kyle \(Volt\)" <a-bkyle@xxxxxxxxxxxxx>
Date: Tue, 18 May 2004 15:48:39 -0700
Hello,
 
I looked this up in the FAQ's but I didn't find it.
 
I'm trying to walk through nodes that are surrounded by text. An unknown
number of nodes can be embedded.
 
<test>
    <c>This is a <a cref="test" /> of the emergency <x>broadcast</x>
system.</c>
    <d>this is not supported</d>
</test>
 
I want to output:
 
<doc>This is a <b>test</b> of the emergency <i>broadcast</i>
system</doc>
 
I tired this, but I am missing my <a> and <x> nodes on output.  I tried
inserting <apply-templates> everyplace I could think of inside the
template matching c, but I am missing some trick.
 
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform
<BLOCKED::http://www.w3.org/1999/XSL/Transform> "
 xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:output indent="yes" />
 
<xsl:template match="/">
    <doc>
        <xsl:apply-templates />
    </doc>
</xsl:template>
 
<xsl:template match="c">
    <xsl:for-each select="text()">
        <xsl:value-of select="."/>
    </xsl:for-each>
    <!-- my confusion: where does apply-templates go? -->
</xsl:template>
 
<xsl:template match="a">
    <b><xsl:value-of select="@ref" /></b>
</xsl:template>
 
<xsl:template match="i">
    <b><xsl:value-of select="." /></b>
</xsl:template>
 
<!-- so I don't output the text twice and to skip the unsupported d
tag-->
<xsl:template match="*|text()">
     <xsl:apply-templates />
</xsl:template>
 
</xsl:stylesheet>
 
What am I missing?
 
Thanks so much for your help. Pointing me to a FAQ will be just fine. I
have a feeling it's been answered a hundred times before.
 
bruce

Current Thread