Subject: Re: Can I access elements in the output tree? From: Peter Paulus <paulus@xxxxxxxx> Date: Thu, 2 Nov 2000 17:19:55 -0400 (EST) |
I've been able to setup this scenario in Xalan version 1.2. There is a side-effect to this (With Xalan?) if your output method is xml: The xml-processing instruction (<?xml version='1.0'?> appears after the you have inserted the node-set into the final result tree with <xsl:copy-of select='$xxx'/>. Effectivelly the xml processing instruction is at the end of the output. I tried to insert a <xsl:processing-instruction name='xml'/> into the final output tree just before copying the node-set. This however is not allowed. Inserting a <xsl:comment/> moved the xml processing instruction to the front of the output again, even before the comment gets inserted. Template rules should start from the / element of the input document. Here's an updated version of Michael's scenario. <?xml version='1.0' encoding='ISO-8859-1'?> <xsl:transform version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:xalan='org.apache.xalan.xslt.extensions.Nodeset' extension-element-prefixes='xalan' > <xsl:output method='xml' encoding='ISO-8859-1' omit-xml-declaration='no' media-type='application/qxml'/> <xsl:template match='/'> <xsl:variable name='output'> <document> <page index='1'>...</page> <page index='2'>...</page> </document> </xsl:variable> <xsl:comment/> <xsl:apply-templates select='xalan:nodeset($output)'/> <xsl:copy-of select='$output'/> </xsl:template> <xsl:template match='/document'> <apply-templates/> </xsl:template> <xsl:template match='/document/page[@index = "1"]'> ... </xsl:template> <xsl:template match='/document/page[@index != "1"'> ... </xsl:template> </xsl:transform> With kind regards, Peter Paulus on 10/27/00 1:11 PM, Kay Michael at Michael.Kay@xxxxxxx wrote: >> Would it be possible to insert elements in the output tree >> and subsequently access them? If so, would there be any restrictions? > > You can create a result tree fragment and then access it using the > node-set() extension function that comes with most popular XSLT processors. > You can't access data once it's written to the final result tree, though. > (There's a good reason for this, most processors don't actually construct > the result tree in memory, they serialize each node as soon as it is > written). But that's not a restriction, you write: > > <xsl:template match="/"> > <xsl:variable name="xxx"> > ... normal processing ... > </xsl:variable> > <xsl:apply-templates select="xx:node-set($xxx)" mode="phase2"/> > <xsl:copy-of select="$xxx"/> > </xsl:template> > > This has the effect you describe. > > Mike Kay > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [newbie]use of xsl:if {RE: XSL , Mike Brown | Thread | Re: Can I access elements in the ou, Mike Brown |
Re: Re: XML Certification, Dimitre Novatchev | Date | Re: dynamically change xpath expres, Edwin Glaser |
Month |