Hi all, I have an xml section like this: ... <summary> this year we earn <benefit>5,000</benefit> dollars,.... </summary> ... in the declaration part <!ELEMENT summary ANY > I am using XSLT to output the xml file to HTML format, how can I output the whole summary section and only make the 5,000 green color. Clara -- thank you so much for your help
clara wrote: > I have an xml section like this: > > ... > <summary> > this year we earn <benefit>5,000</benefit> dollars,.... > > > </summary> > ... > in the declaration part > > <!ELEMENT summary ANY > > > I am using XSLT to output the xml file to HTML format, how can I output the > whole summary section and only make the 5,000 green color. <xsl:template match="summary"> <p><xsl:apply-templates/></p> </xsl:template> <xsl:template match="benefit"> <span style="color: green;"> <xsl:apply-templates/> </span> </xsl:template> -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/
Hi Martin, I usually use <xsl:value-of select="."> to output a tag's content, what' s the different between<xsl:value-of select="."> and<xsl:apply-templates />? Clara -- thank you so much for your help "Martin Honnen" wrote: > clara wrote: > > > I have an xml section like this: > > > > ... > > <summary> > > this year we earn <benefit>5,000</benefit> dollars,.... > > > > > > </summary> > > ... > > in the declaration part > > > > <!ELEMENT summary ANY > > > > > I am using XSLT to output the xml file to HTML format, how can I output the > > whole summary section and only make the 5,000 green color. > > <xsl:template match="summary"> > <p><xsl:apply-templates/></p> > </xsl:template> > > <xsl:template match="benefit"> > <span style="color: green;"> > <xsl:apply-templates/> > </span> > </xsl:template> > > -- > > Martin Honnen --- MVP XML > http://JavaScript.FAQTs.com/ >
clara wrote: > I usually use <xsl:value-of select="."> to output a tag's content, what' s > the different between<xsl:value-of select="."> and<xsl:apply-templates />? <xsl:value-of select="."/> outputs the string value of the context node while <xsl:apply-templates/> processes all child nodes, making sure that any child elements can be processed by matching templates. So with your original markup and <xsl:template match="summary"> <xsl:value-of select="."/> </xsl:template> you get a text node with the text "this year we earn 5,000 dollars,...." while with my suggestion <xsl:template match="summary"> <p><xsl:apply-templates/></p> </xsl:template> <xsl:template match="benefit"> <span style="color: green;"> <xsl:apply-templates/> </span> </xsl:template> you get <p>this year we earn <span style="color: green;">5,000</span> dollars,....</p> a 'p' element with three child nodes, a text node, a 'span' element with the style you want and a text node. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/