Subject: Re: [xsl] Complete newbie stupid question From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Thu, 1 Aug 2002 19:20:47 +0100 |
Hi Sandra, > Hi, I'm new to the list, to XML, to XSL, XSLT and pretty much > everything related. Welcome! > I am trying to do what seems like a simple operation. I just want a > stylesheet that calls a template in which nested templates specify > formatting for specific nodes. Seems simple. Seemed simple for the > first 3 days I tried to make it work. I am now a blithering idiot > who can hardly spell XML. Can someone please refer me to a good > source that can help me sort this out? Or better yet, show me an > example? You sound like you're in the target audience for my book "Beginning XSLT", which actually introduces you to the important bits of XML as well as XSLT. Available from all good booksellers, as they say... > I have been attempting the following: > > <?xml version="1.0" encoding="UTF-8"?> > <xsl:stylesheet version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns:fo="http://www.w3.org/1999/XSL/Format"> If you're creating HTML, there's no need to include the XSL-FO namespace. > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"/> This isn't doing anything, so you can safely leave it out. > <xsl:output method="html" version="4.0" encoding="UTF-8" indent="yes"/> > > <xsl:template match= "/"> > </xsl:template> This will cause a problem. You're telling the processor that whenever it's asked to process the root node of a document, do nothing. Unfortunately, when you run a transformation, the entire result of the transformation is the result of transforming the root node of the source document. So if you have a template like this in your stylesheet, you're guaranteed not to get any output. Either remove this template or replace it with something that says "when you're told to process the root node, process its children": <xsl:template match="/"> <xsl:apply-templates /> </xsl:template> This is the template that's built-in for processing the root node, so if you don't have a template that matches the root node, this is the one that will be used anyway. > <xsl:template match="Head1"> > <html> > <font face="Arial" color="black" size="24" > style="bold"/> > <br/> > </html> > </xsl:template> > <xsl:apply-templates/> > </xsl:template> Erm... I don't think that's well-formed XML -- you seem to have a stray xsl:template end tag hanging around. What you meant is: <xsl:template match="Head1"> <html> <font face="Arial" color="black" size="24" style="bold" /> <br /> <xsl:apply-templates /> </html> </xsl:template> or something along those lines (the font element won't have any effect, I think, since it's empty, so you may as well delete it). The important thing is that the instruction xsl:apply-templates goes at the place in the template where you want the result of processing the result of the document to be inserted. So in this case, if you want the result of processing the children of the Head1 element to be put inside the html element, then that's where you need to put the xsl:apply-templates instruction. All the templates themselves go at the top level of the stylesheet, all at the same level. You don't have templates nested inside other templates. The xsl:apply-templates indicates where the result of processing should go; the template definitions state what to do when the processor gets to a particular kind of element. Have another go and feel free to post here again if you're not getting what you want. Supplying the source XML that you're processing and a sample result that you want to get helps as well. Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Complete newbie stupid questi, Sandra Mcdonnell | Thread | Re: [xsl] Complete newbie stupid qu, Mike Brown |
[xsl] Complete newbie stupid questi, Sandra Mcdonnell | Date | Re: [xsl] Complete newbie stupid qu, Mike Brown |
Month |