Subject: XSLT: decorating a grammatical tree From: OGERARDIN@xxxxxxxxxxxxxxxxxxxxxxx Date: Wed, 10 May 2000 16:18:07 +0200 
Here's my problem: imagine an XML document that represents the results of a grammatical analysis, say of an expression. Only terminals have a value. I'd like to write an XSL stylesheet that computes the values of other nodes. Example: Suppose a very simple grammar for expressions: exp ::= addexp addexp::= multexp  addexp opadd multexp  addexp opsub multexp multexp ::= primaryexp  multexp opmult primaryexp  multexp opdiv primaryexp primaryexp ::= litteral  paropen exp parclose Now take "2 + 3" as input; according to the above grammar, it translates to: <exp> <addexp> <addexp> <multexp> <primaryexp> <litteral value="2/> </primaryexp> </multexp> </addexp> <opadd/> <multexp> <primaryexp> <litteral value="3"/> </primaryexp> </multexp> </addexp> </exp> I'm trying to write an XSL stylesheet that would translate the above to <exp value="5"> <addexp value="5"> <addexp value="2"> <multexp value="2"> <primaryexp value="2"> <litteral value="2/> </primaryexp> </multexp> </addexp> <opadd/> <multexp> <primaryexp value="3"> <litteral value="3"/> </primaryexp> </multexp> </addexp> </exp> I thought of doing something like this: <xsl:template match="addexp"> <xsl:choose> <xsl:when test="opadd"> <! we're in the case addexp ::= addexp opadd multexp > <xsl:copy> <! copy the current node to result tree > <xsl:applytemplates/> < copy and process children > <xsl:attribute name="value"><xsl:valueof select="number(addexp/@value) + number(multexp/@value)"/></xsl:attribute> <! compute the value > </xsl:copy> </xsl:when> (...) </xsl:template> Of course, this won't work because the expression "number(addexp/@value) + number(multexp/@value)" applies to the source tree, not the result tree, and in the source tree nonterminal nodes don't have a value attribute... So, does anyone have an idea of how I could achieve this transformation with XSL? Thanks, Olivier ogerardin@xxxxxxxxxxxxxxxxxxxxxxx Visit us at http://www.clearstream.com IMPORTANT MESSAGE Internet communications are not secure and therefore Clearstream International does not accept legal responsibility for the contents of this message. The information contained in this email is confidential and may be legally privileged. It is intended solely for the addressee. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. Any views expressed in this email are those of the individual sender, except where the sender specifically states them to be the views of Clearstream International or of any of its affiliates or subsidiaries. END OF DISCLAIMER XSLList info and archive: http://www.mulberrytech.com/xsl/xsllist
Current Thread 


< Previous  Index  Next > 

Re: xsl:variable, Sebastian Rahtz  Thread  Re: XSLT: decorating a grammatical , David Carlisle 
Re: xsl:variable, Sydney  Date  RE: Outstanding Argument!, Medina, Edward 
Month 