问题描述
我想在 item 内添加子列表,在列表 para 内添加脚注文本:
I want to add the sublist inside item and footnote text inside list para:
我的源xml:
<body>
<p>blahblah</p>
<ul outputclass="l1">
<li outputclass="lt1">blahblah</li>
<li outputclass="lt1">blahblah</li>
<li outputclass="lt1">blahblah
<ul outputclass="l2">
<li outputclass="lt2">blahblah</li>
<li outputclass="lt2">blahblah<fn><p>blah</p></fn></li>
<li outputclass="lt2">blahblah
<ul outputclass="l3">
<li outputclass="lt3">blahblah<fn><p>blah</p></fn></li>
<li outputclass="lt3">blah<fn><p>blah</p></fn>blah</li>
<li outputclass="lt3">blahblah</li>
</ul></li>
</ul></li>
<li outputclass="lt1">blahblah</li>
<li outputclass="lt1">blahblah</li>
</ul>
<p>blahblah</p>
</body>
myxslt
<?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="2.0">
<xsl:template match="p">
<para>
<xsl:apply-templates/>
</para>
</xsl:template>
<xsl:template match="ul[@outputclass='l1']">
<itemizedlist type="•">
<xsl:apply-templates/>
</itemizedlist>
</xsl:template>
<xsl:template match="ul[@outputclass='l2']">
<itemizedlist type="•">
<xsl:apply-templates/>
</itemizedlist>
</xsl:template>
<xsl:template match="ul[@outputclass='l3']">
<itemizedlist type="•">
<xsl:apply-templates/>
</itemizedlist>
</xsl:template>
<xsl:template match="li[@outputclass='lt1']">
<item>
<xsl:apply-templates/>
</item>
</xsl:template>
<xsl:template match="li[@outputclass='lt2']">
<item>
<xsl:apply-templates/>
</item>
</xsl:template>
<xsl:template match="li[@outputclass='lt3']">
<item>
<xsl:apply-templates/>
</item>
</xsl:template>
<xsl:template match="li/text()[normalize-space()]">
<para>
<xsl:value-of select="."/>
</para>
</xsl:template>
</xsl:stylesheet>
输出我在子列表的末尾得到para关闭,作为子列表后的para关闭:
output i am getting para closing at the end of the sub list needed as para closing after sublist:
<body>
<para>blahblah</para>
<itemizedlist type="•">
<item><para>blahblah</para></item>
<item><para>blahblah</para></item>
<item><para>blahblah</para>
<itemizedlist type="•">
<item><para>blahblah</para></item>
<item><para>blahblah</para><footnote><para>blah</para></footnote></item>
<item><para>blahblah</para>
<itemizedlist type="•">
<item><para>blahblah</para><footnote><para>blah</para></footnote></item>
**<item><para>blah</para><footnote><para>blah</para></footnote><para>blah</para></item>**
<item><para>blahblah</para></item>
</itemizedlist></item>
</itemizedlist></item>
<item><para>blahblah</para></item>
<item><para>blahblah</para></item>
</itemizedlist>
<para>blahblah</para>
</body>
但是像子列表一样需要的输出应该在段落结束和项目结束之间以及 item-para 内的脚注之间,如下所示:
but needed output as like sublist should be between para closing and item closing and footnote inside item-para as shown below :
<body>
<para>blahblah</para>
<itemizedlist type="•">
<item><para>blahblah</para></item>
<item><para>blahblah</para></item>
**<item><para>blahblah</para>**
<itemizedlist type="•">
<item><para>blahblah</para></item>
<item><para>blahblah</para></item>
**<item><para>blahblah<footnote><para>blah</para></footnote></para>**
<itemizedlist type="•">
<item><para>blahblah<footnote><para>blah</para></footnote></para></item>
**<item><para>blah<footnote><para>blah</para></footnote>blah</para></item>**
<item><para>blahblah</para></item>
**</itemizedlist></item>**
**</itemizedlist></item>**
<item><para>blahblah</para></item>
<item><para>blahblah</para></item>
</itemizedlist>
<para>blahblah</para>
</body>
有可能是粗体吗?如果可能,请推荐我
Is it possible as bolded one.If possible please suggest me
提前致谢.
推荐答案
你还没有真正解释哪些是将节点包装到 para
的标准,这里是一个使用 for-each-group group-adjacent="boolean(self::ul)"
将任何不是 ul
元素的相邻节点包装到 para
元素中:
You haven't really explained which are the criteria to wrap nodes into para
, here is a sample using for-each-group group-adjacent="boolean(self::ul)"
to wrap any adjacent nodes not being ul
elements into para
elements:
<?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="2.0">
<xsl:template match="@* | node()" mode="#all">
<xsl:copy>
<xsl:apply-templates select="@* | node()" mode="#current"/>
</xsl:copy>
</xsl:template>
<xsl:template match="p">
<para>
<xsl:apply-templates/>
</para>
</xsl:template>
<xsl:template match="ul[@outputclass='l1'] | ul[@outputclass='l2'] | ul[@outputclass='l3']">
<itemizedlist type="•">
<xsl:apply-templates/>
</itemizedlist>
</xsl:template>
<xsl:template match="li[@outputclass='lt1'] | li[@outputclass='lt2'] | li[@outputclass='lt3']">
<item>
<xsl:for-each-group select="node()" group-adjacent="boolean(self::ul)">
<xsl:choose>
<xsl:when test="current-grouping-key()">
<xsl:apply-templates select="current-group()"/>
</xsl:when>
<xsl:otherwise>
<para>
<xsl:apply-templates select="current-group()" mode="preserve"/>
</para>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</item>
</xsl:template>
</xsl:stylesheet>
这篇关于需要在结束段和项目之间添加子列表,并在结束段内添加脚注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!