[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: xsl:if to separate child elements
At 06:35 PM 09/25/2000 -0700, pmitra wrote:
I am somehow really stuck trying to separate out different child elements using <xsl:if>. Please help with the following situation if possible: When you say "in sequence," you mean in the order they appear in the XML document, right? If not, please explain. If so, please read on. Forget the for-each. Like Chris Bayes (I think) says, "Newbie rule #1: Don't use xsl:for-each." (It often doesn't do what newcomers might think it does.) For that matter, you don't need any xsl:if's either. This stylesheet: <!-- Template for root <help> element --> <xsl:template match="help"> <!-- Process all children of <help>, i.e. all <helptext> and <helpexample> elems., in doc order --> <xsl:apply-templates /> </xsl:template> <!-- Template for <helptext> elements --> <xsl:template match="helptext"> <!-- Wrap content in <pre> element --> <pre><xsl:value-of select="." /></pre> </xsl:template> <!-- Template for <helpexample> element --> <xsl:template match="helpexample"> <!-- Just output content --> <xsl:value-of select="." /> </xsl:template> ... when applied to your sample XML with Saxon or XT, transforms it to: <pre xmlns="http://www.w3.org/TR/REC-html40"> This is a descriptive note </pre> This is an example <pre xmlns="http://www.w3.org/TR/REC-html40"> This is another line of text </pre> When viewed in IE5, either this HTML output from Saxon/xt *or* the XML when linked to the stylesheet, displays: This is a descriptive note <--displays in fixed font This is an example <--displays in proportional font This is another line of text <--displays in fixed font Is that the result you wanted? ========================================================== John E. Simpson | "If you were going to http://www.flixml.org | shoot a mime, would you use XML Q&A: http://www.xml.com | a silencer?" (Steven Wright) XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|