Subject: Re: [xsl] numbering output and other newbie issues From: "Jon Gorman" <jonathan.gorman@xxxxxxxxx> Date: Wed, 1 Mar 2006 08:58:22 -0600 |
> This gives me something close to the solution I am looking for. > However, some of my answers have text that I have tagged with > <us></us> for underscore like this: > > <item> 1. Millions of Americans <answer><us>watch</us> displays of > fireworks on the > Fourth of July.</answer> > > I would like those tags to appear in the output. I have tried > <xsl:copy-of select "us" /> in several positions, but the output > doesn't change. Probably because you're putting it somewhere that it is never actually reached. Have you tried <xsl:template match="us"> <xsl:copy-of select="." /> </xsl:template>? > I am puzzled by the several random returns left in the output as in > answers 8 and 9. But I am feeling good about the script. Here is my > understanding of what I am doing in each section. > First I am stripping out white spaces from every element (or trying to!). The source XML had those return lines. White-space striping removes text nodes that only contain whitespace, not necessarily any whitespace within the node. See http://www.w3.org/TR/xslt#strip > Then I am selecting NameLine, Item, definitions, and directions. I think there's some confusion here. You're not "selecting" these anywhere. Templates tells you what should happen when you do select elements. You select elements by <xsl:apply-templates select="foo" />. Remember there are default templates as well. I > I don't understand > why I am selecting item. I will try commenting out that line to see > if it changes the output. As far as I can tell, you don't ever directly select item. What you're doing is saying "When in processing an apply-templates is called and the node matches this template the best, produce this output". > Then I am selecting topic, adding a return before it and two returns > after it. The apply-templates passes all this topic to output--is > that right? If not to output, then it goes on...to the next template? Your mental model seems a bit wonky here. > I think I got the aha you spoke of. That is, that when you match a > node, you are removing it (perhaps to a processing cache of some > kind). If you don't do anything with that node, then it remains in > process until you call it out, so to speak. If you don't call it it > out, it goes away to some cyber graveyard. Not really. It's more accurate to say that you are saying to print nothing. In another language imagine: void foo(obj object) {} You can call foo all you like, it just doesn't do anything. > > Am I getting close to a clearer understanding of the basic process? Hard to tell, I've only skimmed this thread but you still seem to be guessing your way through it. The first thing to realize is that there are default templates: see http://www.w3.org/TR/xslt#built-in-rule. or in short: <xsl:template match="*|/"> <xsl:apply-templates/> </xsl:template> <xsl:template match="*|/" mode="m"> <xsl:apply-templates mode="m"/> </xsl:template> <xsl:template match="text()|@*"> <xsl:value-of select="."/> </xsl:template> I'd recommend the following exercise. Add the default templates to your stylesheet to make it easier to do this. Print out your stylesheet, get a blank piece of paper. Now look at your XML document. We start at the / node, which contains the child element Story. Find which xsl:template match="." expression seems the most specific match for the / node. Follow the instructions in that node. Remember that without a select attribute xsl:apply-templates will look for templates that apply for all child element nodes and child text nodes. It won't apply to attributes though, so be careful about that. In this case, the built-in template that matches the best is <xsl:template match="*|/"> <xsl:apply-templates /> </xsl:template> So we apply-templates to all the children, which in this case is Story. We again look for the best match. <xsl:template match="*|/"> <xsl:apply-templates /> </xsl:template> I'll leave it as an exercise for you to finish the rest of this processing. In the end what you get on the sheet should match your output here, except probably for some spacing issues. Hopefully you'll get a better understanding of the process though. Jon Gorman
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
AW: [xsl] XHTML to Cals table conve, Huditsch, Roman \(LN | Thread | Re: [xsl] numbering output and othe, Wendell Piez |
RE: [xsl] Sort multiple xml files w, Michael Kay | Date | [xsl] XSL-List Guidelines, B Tommie Usdin |
Month |