Subject: Re: Lopping off Element Type names with substring-after From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Mon, 14 Aug 2000 19:57:16 +0100 |
John (or do you prefer JR?), I'm not sure I understand how you're getting what you're getting. Did you simplify the templates for posting? ><!-- to copy the whole tree --> > > <xsl:template match="/"> > <xsl:copy-of select="@*|*|text()" /> > </xsl:template> The source of your problems is misunderstanding xsl:copy-of. xsl:copy-of copies everything you select. All of it. Literally. No filters, nothing. Since you don't have any xsl:apply-templates in your root-node-matching template, then it shouldn't go on and do anything else - you should just get a literal copy of your input (which of course you didn't want anyway), which is why I wonder whether you simplified it. ><!-- to trim most, but not all, the tag names --> > > <xsl:template match="//*[not(contains(name(), 'AndKeep')) > and not(contains(name(), 'OrKeep'))]"> > <xsl:copy-of select="*[substring-after(name(), '.')]" /> > </xsl:template> This says: For any element that is a descendent of the root node and whose name does not include 'AndKeep' and does not contain 'OrKeep', make a copy of those of its children that have a name that has any value after the '.' within the name. One minor thing: you never need to include // at the start of a match pattern - all nodes are descendents of the root node. I think that what you wanted to say was: For any element whose name does not include 'AndKeep' or 'OrKeep', create an element with a name that is everything after the '.' of the current name, containing the result of applying the same templates to its content. I'm just going to concentrate on those element names that contain '.' at the moment: <xsl:template match="*[not(contains(name(), 'AndKeep') or contains(name(), 'OrKeep')) and contains(name(), '.')]"> <xsl:element name="{substring-after(name(), '.')}"> <xsl:apply-templates /> </xsl:element> </xsl:template> You also need a template that matches those elements whose names *do* contain 'AndKeep' or 'OrKeep', or don't contain a '.' (i.e. all the other elements) and create 'copies' of those elements (actually create an element with the same name, and apply templates to the content): <xsl:template match="*"> <xsl:element name="{name()}"> <xsl:apply-templates /> </xsl:element> </xsl:template> All your root-node matching template needs to do is apply templates (which means that there's no need for one at all unless you're doing extra stuff as well, since the built-in template will do the job for you). I hope that this helps, Jeni Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Lopping off Element Type names with, John Robert Gardner | Thread | Line Numbering, Darrin Bishop |
Including http:// as value of href, prashanth . b . rao | Date | Re: Line Numbering, David_Marston |
Month |