Subject: Re: [xsl] how to replace an XML tag with a result tree and parse it again From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Mon, 4 Jun 2001 12:24:53 +0100 |
Hi Janning, > then i am in trouble, because the tree in $mytoc doesnt belong to > the main xml tree. So here is my question: How can i achieve that > templates replace something in the input tree and the Stylesheet > behaves as it was always there? Your best bet is to do a two-pass solution, where the first pass creates the XML that you want to use as the source of the next pass. These passes could be done by separate stylesheets, or you could do them in the same stylesheet if you're prepared to use a node-set() extension function (which I think you are, given how you're describing addressing it at the moment). Build a controlling template to manage the transformation. I usually use the root-node-matching template for this. Within it, you want to apply templates to the source as it stands in 'substitute' mode and then apply templates to the result of that in the default mode: <xsl:template match="/"> <xsl:variable name="substituted"> <xsl:apply-templates mode="substitute" /> </xsl:variable> <xsl:apply-templates select="exsl:node-set($substituted)/*" /> </xsl:template> Have your toc-matching template apply only in 'substitute' mode, replacing the toc element with the content that you want it to replace: <xsl:template match="toc" mode="substitute"> <itemizedlist> <listitem>Chapter 1</listitem> <listitem> Chapter 2</listitem> ... </itemizedlist> </xsl:template> For everything else in 'substitute' mode, you just want the identity template: <xsl:template match="@*|node()" mode="substitute"> <xsl:copy> <xsl:apply-templates select="@*|node()" /> </xsl:copy> </xsl:template> The rest of the templates can stay the same. The only things that will differ between the source document and the one that you use as the basis of the main part of the transformation is that the toc element will be replaced and that the base URI of the document will be different. The latter shouldn't matter unless you're using the document() function with two arguments anywhere? I hope that 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 -> |
---|---|---|
BladeRunner XSL support (was: Re: [, Martin Dransfield | Thread | Re: [xsl] XPath, starts with ?, Jeni Tennison |
Re: [xsl] XSL and White Space help , David Carlisle | Date | Re: [xsl] XPath, starts with ?, Jeni Tennison |
Month |