我有帶有腳注(描述為'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,' ',@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
------------
*
uj5u.com熱心網友回復:
我不確定我是否理解
我需要的另一件事是一旦有 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:iterate或xsl:for-each或包裝插入xsl:apply-templates足夠的標記(例如div或ul/li或)來處理。br
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/489250.html
