Subject: Re: [xsl] Best Practices for inline elements From: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx> Date: Fri, 5 Jul 2002 14:53:12 -0400 |
[Brad Miller] Can any one give me some advice on how to handle inline elements. For example: bold, italics, underline and inline images. I am formatting all of my XML docs to HTML and I really don't know how to handle the inline stuff. I have items that need to be bold but are scattered through out the documents. example: <para> Some text <bold>text</bold> more text <italics>text</italics> more text <image src="icon.png" />. Some more text. </para> All of my files have to be generated on the fly through IE. So far I have not been able to find any examples of code like this. Is this just not done? Or is it just so simple I can't see it. So far everything I have tried has either given me the inline elements formatted after the paragraph but never formatted "inline", or just nothing at all. [Tom P] To some extent it may depend on how you have designed your stylesheet and how much nesting there can be. Something along the following lines will usually do what you want ( I made "doc" the document element, and for simplicity left off the head and body elements) : <xsl:template match="/doc"> <html> <xsl:apply-templates/> </html> </xsl:template> <xsl:template match='para'> <xsl:apply-templates/> </xsl:template> <xsl:template match='bold'> <b><xsl:apply-templates/></b> </xsl:template> <xsl:template match='italics'> <i><xsl:apply-templates/></i> </xsl:template> <xsl:template match='image'> <img src='{@src}'/> </xsl:template> <!-- Add similar templates for other "inline" elements --> In each template, the xsl:apply-templates examines the contents of the current set of nodes and looks for templates to apply to each node it finds. This picks up your inline elements. If there is no other template available, xslt applies the built-in default template, which picks out the character data - that is, the text content - of the element it is processing. >From your sample xml, it doen not look as if anything more complicated is needed. Cheers, Tom P XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Best Practices for inline, David Carlisle | Thread | RE: [xsl] Best Practices for inline, Brad Miller |
Re: [xsl] more encoding woe, Mike Brown | Date | Re: [xsl] tags?, Wendell Piez |
Month |