XSLT 3.0:使用累加器,如何累加值并在它们之间换行以及如何重置累加器

或者哟

我有带有脚注(描述为'note'标签)的xml(如下所述),我想将其变成一个分为页面的-html文档,其中直到'eop'标签在累加器'notes'中累积'note'标签然后将目前积累的所有'note'标签全部拉出并显示并关闭页面。转到下一页等等。每个单独的脚注应该在一个单独的行中,为此,您必须将每个单独的脚注包装在 div 标签中(我不能这样做),或者在每个新脚注之前移动到下一行(您在下面的 xslt 中看到的内容,但是不工作)

我需要的另一件事是一有 eop 就重置 oclator。我添加了 (<xsl: accumulator-rule match = "eop" select = "''" />) 但它在显示之前结束了以下 xslt 描述了我做了什么,没有做什么需要有人帮助我吗?

xml:

<?xml version="1.0" encoding="UTF-8"?>
<dataRoot>
    <article>
        <point>
            <p>aaa</p>
            <note marker="*" >note 1</note>
            <p>bbb
                <eop>100</eop>
            </p>
            <p>ccc
                <note marker="*">note 2</note>
            </p>
        </point>
        <point>
            <note marker="**">note 3</note>
            <p>ddd</p>
            <p>eee</p>
        </point>
        <point>
            <note marker="***">note 4</note>
        </point>
        <eop>101</eop>
    </article>
    <article>
        <note marker="*">note 5</note>
        <point>
            <p>fff</p>
            <p>ggg
                <eop>102</eop>
            </p>
        </point>
        <point>
            <note marker="*">note 6</note>
        </point>
    </article>
</dataRoot>

xslt:

<?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" exclude-result-prefixes="xs" version="3.0" >
    <xsl:mode use-accumulators="#all" streamable="no"/>
    <xsl:output omit-xml-declaration="no" indent="yes"/>
    <xsl:accumulator name="notes" initial-value="''">
        <xsl:accumulator-rule match="note" select="concat($value,'&#10;',@marker,.)"/>
    </xsl:accumulator>
    <xsl:template match="/">
        <html>
            <head>
                <style type="text/css">
                 
                </style>
            </head>
            <body>
                <xsl:apply-templates />
            </body>
        </html>
    </xsl:template>
    <xsl:template match="eop">
        <div class="line">
            -- </div>
        <div class="note">
            <xsl:value-of select="accumulator-before('notes')"/>
        </div>
        <div class="eop">
            <xsl:value-of select='.' />
        </div>
        <div class="line">
            ------------ </div>
    </xsl:template>
    <xsl:template match="article" >
        <xsl:apply-templates />
    </xsl:template>
    <xsl:template match="point" >
        <div class="point">
            <xsl:value-of select="text()"></xsl:value-of>
            <xsl:apply-templates />
        </div>
    </xsl:template>
    <xsl:template match="p" >
        <xsl:apply-templates />
    </xsl:template>
    <xsl:template match="note" >
        <span class="authorialNote">
            <xsl:value-of select="@marker"/>
        </span>
    </xsl:template>
</xsl:stylesheet>

输出html:

aaa * bbb
--
*note 1
100
------------
ccc *
** ddd eee
***
--
*note 1 *note 2 **note 3 ***note 4
101
------------
*
fff ggg
--
*note 1 *note 2 **note 3 ***note 4 *note 5
102
------------
*

马丁霍南

我不确定我是否理解

我需要的另一件事是一有 eop 就重置 oclator。我添加了 ( <xsl:accumulator-rule match = "eop" select = "''" />) 但它在显示之前结束了

如果您想在遇到eop该代码时重置应该是正确的;但是,当您尝试在匹配时读出该值时,eop我想您宁愿用<xsl:accumulator-rule match = "eop" select = "''" phase="end"/>.

至于插入换行符,也许不收集单个字符串值作为累加器值,而是收集字符串序列,例如

<xsl:accumulator name="notes" as="xs:string*" initial-value="()">
    <xsl:accumulator-rule match="note" select="$value, @marker || ."/>
    <xsl:accumulator-rule match="eop" select="()" phase="end"/>
</xsl:accumulator>

然后,accumulator-before('notes')为您提供一个字符串序列,您可以使用xsl:iteratexsl:for-each或包装插入xsl:apply-templates足够的标记(例如divul/li或)来处理。br

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章