[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
Re: [Accumulators] Another stupid question
A single pass will do:
<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="block" expand-text="yes">
<xsl:variable name="height" as="xs:double" select="3.5"/>
<xsl:message>Adding block height {@id} : {$height}</xsl:message>
<xsl:sequence select="$value[1] + $height"/>
</xsl:accumulator-rule>
</xsl:accumulator>
<xsl:template match="block">
<xsl:copy>
<xsl:attribute name="y" select="accumulator-after('blockHeight')[1]"/>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
On 06.10.2020 23:31, Christophe Marchand cmarchand@xxxxxxxxxx wrote:
Ok, thanks a lot, Martin and Gerrit. So I must use a two pass strategy
if I'm not able to directly calculate widht on content.
Not a good news, but, thanks to you, I now know how to solve my problem !
Best regards,
Christophe
Le 06/10/2020 C 23:20, Imsieke, Gerrit, le-tex gerrit.imsieke@xxxxxxxxx
a C)critB :
The private:block elements are trees of their own and they have their
own accumulator values (that are available in the template that
matches private:block). But they don't add to the 'blockHeight'
accumulator of the main document.
On 06.10.2020 22:57, Christophe Marchand cmarchand@xxxxxxxxxx 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"
B B xmlns:xs="http://www.w3.org/2001/XMLSchema"
B B xmlns:private="top:marchand"
B B exclude-result-prefixes="#all"
B B version="3.0">
B B <xsl:output method="xml" indent="true"/>
B B <xsl:mode on-no-match="shallow-copy" use-accumulators="#all"/>
B B <xsl:accumulator name="blockHeight" as="xs:double"
initial-value="0.0">
B B B B <xsl:accumulator-rule match="page">
B B B B B B <xsl:message>Reset block height to 3.2</xsl:message>
B B B B B B <xsl:sequence select="3.2"/>
B B B B </xsl:accumulator-rule>
B B B B <xsl:accumulator-rule match="private:block">
B B B B B B <xsl:message>Adding block height {@id} : {@height}</xsl:message>
B B B B B B <xsl:sequence select="$value + xs:double(@height)"/>
B B B B </xsl:accumulator-rule>
B B </xsl:accumulator>
B B <xsl:template match="block">
B B B B <xsl:variable name="height" as="xs:double" select="3.5"/>
B B B B <!-- produce some output -->
B B B B <xsl:variable name="TempTree" as="element(private:block)">
B B B B B B <private:block height="{$height}"/>
B B B B </xsl:variable>
B B B B <xsl:apply-templates select="$TempTree"/>
B B B B <xsl:copy>
B B B B B B <xsl:attribute name="y"
select="accumulator-after('blockHeight')"/>
B B B B B B <xsl:apply-templates select="node() | @*"/>
B B B B </xsl:copy>
B B </xsl:template>
B B <xsl:template match="private:block">
B B B B <xsl:message>private:block matched</xsl:message>
B B </xsl:template>
B B <xsl:template name="xsl:initial-template">
B B B B <xsl:variable name="content" as="document-node()">
B B B B B B <xsl:document>
B B B B B B B B <doc>
B B B B B B B B B B <page id="p1">
B B B B B B B B B B B B <block id="b1">
B B B B B B B B B B B B B B <!-- arbitrary content -->
B B B B B B B B B B B B </block>
B B B B B B B B B B B B <block id="b2">
B B B B B B B B B B B B B B <!-- another arbitrary content -->
B B B B B B B B B B B B </block>
B B B B B B B B B B </page>
B B B B B B B B B B <page id="p2">
B B B B B B B B B B B B <block id="b3">
B B B B B B B B B B B B B B <!-- arbitrary content -->
B B B B B B B B B B B B </block>
B B B B B B B B B B B B <block id="b4">
B B B B B B B B B B B B B B <!-- another arbitrary content -->
B B B B B B B B B B B B </block>
B B B B B B B B B B </page>
B B B B B B B B </doc>
B B B B B B </xsl:document>
B B B B </xsl:variable>
B B B B <xsl:apply-templates select="$content"/>
B B </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
<- Previous | Index | Next -> |
Re: [Accumulators] Another st, Imsieke, Gerrit, le-
|
Thread |
Re: [Accumulators] Another st, Imsieke, Gerrit, le-
|
Re: [Accumulators] Another st, Imsieke, Gerrit, le-
|
Date |
Re: [Accumulators] Another st, Imsieke, Gerrit, le-
|
|
Month |
|
|
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
RSS 2.0 |
|
Atom 0.3 |
|
|