[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: [Accumulators] Another stupid question
Please use informative subject lines on XSL-List. The list archives are very heavily used, and we believe that most users of the archives search the text and then browse the subject lines to decide what to read. Since it is likely that others will have the same question you do, it is a courtesy to future users of the list to describe the question clearly in your subject line. In this case, for example, you might have used: Why is one accumulator used and another not? Thank you for helping make XSL-List re-useable. -- Tommie > On Oct 6, 2020, at 4:57 PM, Christophe Marchand cmarchand@xxxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > > Hello ! > > I have another question with accumulators. I use accumulators to calculate block height, and then to calculate block locations (y). > > I have this XSL for a repro... > > <?xml version="1.0" encoding="UTF-8"?> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns:xs="http://www.w3.org/2001/XMLSchema" > xmlns:private="top:marchand" > exclude-result-prefixes="#all" > version="3.0"> > > <xsl:output method="xml" indent="true"/> > > <xsl:mode on-no-match="shallow-copy" use-accumulators="#all"/> > > <xsl:accumulator name="blockHeight" as="xs:double" initial-value="0.0"> > <xsl:accumulator-rule match="page"> > <xsl:message>Reset block height to 3.2</xsl:message> > <xsl:sequence select="3.2"/> > </xsl:accumulator-rule> > <xsl:accumulator-rule match="private:block"> > <xsl:message>Adding block height {@id} : {@height}</xsl:message> > <xsl:sequence select="$value + xs:double(@height)"/> > </xsl:accumulator-rule> > </xsl:accumulator> > > <xsl:template match="block"> > <xsl:variable name="height" as="xs:double" select="3.5"/> > <!-- produce some output --> > <xsl:variable name="TempTree" as="element(private:block)"> > <private:block height="{$height}"/> > </xsl:variable> > <xsl:apply-templates select="$TempTree"/> > <xsl:copy> > <xsl:attribute name="y" select="accumulator-after('blockHeight')"/> > <xsl:apply-templates select="node() | @*"/> > </xsl:copy> > </xsl:template> > > <xsl:template match="private:block"> > <xsl:message>private:block matched</xsl:message> > </xsl:template> > > <xsl:template name="xsl:initial-template"> > <xsl:variable name="content" as="document-node()"> > <xsl:document> > <doc> > <page id="p1"> > <block id="b1"> > <!-- arbitrary content --> > </block> > <block id="b2"> > <!-- another arbitrary content --> > </block> > </page> > <page id="p2"> > <block id="b3"> > <!-- arbitrary content --> > </block> > <block id="b4"> > <!-- another arbitrary content --> > </block> > </page> > </doc> > </xsl:document> > </xsl:variable> > <xsl:apply-templates select="$content"/> > </xsl:template> > </xsl:stylesheet> > > When I run this XSL on the sample XML, I have messages displayed : "Reset block height to 3.2", "private:block matched", but never the "Adding block height..." > > According to specification [1], I expect private:block matches accumulator rule, and accumulator value being augmented by block/@height. > > What am I doing wrong ? > > Thanks in advance, > Christophe > > [1] : 18.2.2 https://www.w3.org/TR/xslt-30/#applicability-of-accumulators list item 1 > ====================================================================== B. Tommie Usdin mailto:btusdin@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. https://www.mulberrytech.com 17 West Jefferson Street Phone: 301/315-9631 Suite 207 Direct Line: 301/315-9634 Rockville, MD 20850 Fax: 301/315-8285 ----------------------------------------------------------------------------- --------------------------------------------- Mulberry Technologies: A Consultancy Specializing in XML for Prose Documents ======================================================================
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|