[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: how to display XML nodes having HTML tags
Subject: Re: how to display XML nodes having HTML tags From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Thu, 10 Jun 1999 20:49:18 -0400 |
At 99/06/10 14:21 -0400, Hari Yerram wrote: >Any one know how to display the XML nodes having the HTML tags In effect, you translate the HTML input to the HTML output. >XML node is > >Input: ><XMLNode>Hello<b>XSL List</b></XMLNode> > >Output for the XML node should be >Hello<b>XSL List</b> > >please note that i don't want to process <b> and </b> tags. You'll have to process them, but you can process them to be themselves. You don't mention if you are using IE5 or W3C, but with the W3C version of XSL this is really easy with either the <xsl:copy-of> or <xsl:copy> construct, depending on the richness of your input data. Consider the following if the HTML constructs you have strictly follow the HTML recommendation. You can copy them verbatim as follows: ================8<--------------- T:\hari>type hari.xml <?xml version="1.0"?> <test> <XMLNode>Hello<b>XSL List</b></XMLNode> <XMLNode>Another <img src="http://site/file"/> Test</XMLNode> </test> T:\hari>type hari.xsl <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0"> <xsl:template match="XMLNode"> <!--make a normal paragraph--> <p><xsl:apply-templates/></p> </xsl:template> <!--list all HTML element types here--> <xsl:template match="b|img|pre|samp| p|h1|h2|h3"> <xsl:copy-of select="."/> </xsl:template> </xsl:stylesheet> T:\hari>call xsl hari.xml hari.xsl hari.htm T:\hari>type hari.htm <p>Hello<b>XSL List</b></p> <p>Another <img src="http://site/file"/> Test</p> T:\hari> ================8<--------------- But, if you have non-HTML constructs embedded within the HTML constructs, this would not work, so you can use <xsl:copy> instead. In the test below, I've added some non-HTML markup inside the <b> element you had and then re-ran the above stylesheet ... you can see the non-HTML element was copied verbatim because <xsl:copy-of> copies *everything* about a node. In contrast, <xsl:copy> in the next example only copies the given node (not even the attributes), so one must manually copy the attributes and then apply the templates for the content in order for any non-HTML to get transformed as well. ================8<--------------- T:\hari>type hari2.xml <?xml version="1.0"?> <test> <XMLNode>Hello<b>XSL <XMLNode>abc</XMLNode> List</b></XMLNode> <XMLNode>Another <img src="http://site/file"/> Test</XMLNode> </test> T:\hari>call xsl hari2.xml hari.xsl hari.htm T:\hari>type hari.htm <p>Hello<b>XSL <XMLNode>abc</XMLNode> List</b></p> <p>Another <img src="http://site/file"/> Test</p> T:\hari>type hari2.xsl <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0"> <xsl:template match="XMLNode"> <!--make a normal paragraph--> <p><xsl:apply-templates/></p> </xsl:template> <!--list all HTML element types here--> <xsl:template match="b|img|pre|samp| p|h1|h2|h3"> <xsl:copy select="."> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> </xsl:stylesheet> T:\hari>call xsl hari2.xml hari2.xsl hari2.htm T:\hari>type hari2.htm <p>Hello<b>XSL <p>abc</p> List</b></p> <p>Another <img src="http://site/file"/> Test</p> T:\hari> ================8<--------------- I hope this helps. ....... Ken -- G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (Fax:-0995) Website: XSL/XML/DSSSL/SGML services outline, XSL/DSSSL shareware, stylesheet resource library, conference training schedule, commercial stylesheet training materials, on-line XSL CBT. XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: how to display XML nodes having, G. Ken Holman | Thread | Re: how to display XML nodes having, G. Ken Holman |
WANTED - XML Hotshots, Michael Tan | Date | Re: XSL/CSS = XTL and XFO, Totolaricot |
Month |