Subject: Re: [xsl] A simple basic question From: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx> Date: Mon, 6 May 2002 08:21:45 -0400 |
[Philip Mak] > I looked at various XSL guides, but I still can't figure out how to > transform this: > > <document> > <paragraph>Here is a <bold>bold</bold> word.</paragraph> > <paragraph>Here is an <italic>italic</italic> word.</paragraph> > </document> > > into this: > > <body> > <p>Here is a <b>bold</b> word.</p> > <p>Here is an <i>italic</i> word.</p> > </document> > This result isn't literally possible since it is not well-formed, but I take it that you really meant to close with </body> instead. > The part I have trouble with is the <bold> and <italic>. The thing is > that they could appear anywhere in the document; they're not part of a > rigid structure. It seems that when I use <xsl:value-of > select="paragraph">, the <bold> and <italic> tags inside just get > stripped out. > That's natural since the purpose of value-of is to get the text content. Instead, you have to supply the b and i elements yourself. Exactly how may depend on just what else you want to do, but here's a stylesheet fragment that shows how you can do it. It depends on the built-in template - that handles all elements in the absence of other templates - to get all the text, and the stylesheet adds the p, b, and i elements where needed. <xsl:template match="/"> <body> <xsl:apply-templates/> </body> </xsl:template> <xsl:template match='paragraph'> <p><xsl:apply-templates/></p> </xsl:template> <xsl:template match='bold'> <b><xsl:apply-templates/></b> </xsl:template> <xsl:template match='italic'> <i><xsl:apply-templates/></i> </xsl:template> Cheers, Tom P XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] A simple basic question, Jeni Tennison | Thread | Re: [xsl] A simple basic question, Oleg Tkachenko |
Re: [xsl] A simple basic question, Jeni Tennison | Date | [xsl] XSl, sorting, namespaces and , Ernst Wolthaus |
Month |