|
Subject: Re: [xsl] Adding Missing Elements From: "Joris Gillis" <roac@xxxxxxxxxx> Date: Tue, 13 Sep 2005 21:48:36 +0200 |
"The best way to do this" does not exist, it's amatter of personal personal style.Given these possible variations and based on some processing elsewhere in the document, I would like to make sure that <node> always has <item>B</item> in its list...possibly adding <list> if it is not present.
Can someone give me some suggestions on the best way to do this?
<xsl:stylesheet version="1.0" xmlns:var="myvar" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/>
<var:root> <list> <item>B</item> </list> </var:root>
<xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*" /> </xsl:copy> </xsl:template>
<xsl:template match="node|list|item">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*" />
<xsl:apply-templates select="
$var[current()/self::node][not(current()/list)]|
$var[current()/self::list]/item[not(.=current()/item)]|
node()" />
</xsl:element>
</xsl:template>regards, -- Joris Gillis (http://users.telenet.be/root-jg/me.html) B+Et ipsa scientia potestas estB; - Francis Bacon , Meditationes sacrae
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Adding Missing Elements, J.Pietschmann | Thread | Re: [xsl] Adding Missing Elements, Joris Gillis |
| RE: [xsl] Keeping a map in my XSL, Kevin L. Cobb | Date | Re: [xsl] Keeping a map in my XSL, Jon Gorman |
| Month |