xsl-list
[Top] [All Lists]

[xsl] [XSL 1.0] How to use apply-templates to process a sub-node

2011-02-07 15:51:36
This is a real basic question, I think, but I can't get my head around it. 
Given this XML:

<root>
        <story>
                <Head>This is the title</Head>
                <Body>This is the body <Big>some of it is bold</Big> and some 
isn't</Body>
                <Body>This is some more body text.</Body>
        </story>
</root>

And this XSL:

<xsl:stylesheet>
    <xsl:template match="/">
        <html>
            <body>
                <xsl:apply-templates select="Root" />
            </body>
        </html>
    </xsl:template>
    
    <xsl:template match="Head">
        <h1><xsl:value-of select="."/></h1>
    </xsl:template>
        
    <xsl:template match="Body">
        <p><xsl:value-of select="."/></p>
    </xsl:template>
        
    <xsl:template match="Big">
        <bold><xsl:value-of select="."/></bold>
    </xsl:template>
    
</xsl:stylesheet>

I'm trying to convert the XML to HTML with XSL. I've got it all figured out and 
working, except for the <Big> text. I don't understand how to recursively get 
to the <Big> element when it is a sub-element of <Body>. All the examples I've 
read about in all my books expect the XML to be:

<Body>
        <Big>text here</Big>
</Body>

But this is a different structure, where the <Big> element is in the middle of 
the Body element.

Can anyone shed some light on how I get to the <Big> element with 
apply-templates?

Thanks!


~ Keith











--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>