如何在项目值中移动子列表

时间:2017-08-16 06:51:09

标签: xml xslt-2.0

我想在项目中添加子列表:

我的来源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">blahblah</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

<xsl:template match="p">
    <para>
      <xsl:apply-templates/>
    </para>
  </xsl:template>

<xsl:template match="fn">
    <footnote>
      <xsl:apply-templates/>
    </footnote>
  </xsl:template>

<xsl:template match="ul[@outputclass='l1']">
    <itemizedlist type="&#x2022;">
      <xsl:apply-templates/>
    </itemizedlist>
  </xsl:template>

<xsl:template match="ul[@outputclass='l2']">
    <itemizedlist type="&#x2022;">
      <xsl:apply-templates/>
    </itemizedlist>
  </xsl:template>

<xsl:template match="ul[@outputclass='l3']">
    <itemizedlist type="&#x2022;">
      <xsl:apply-templates/>
    </itemizedlist>
  </xsl:template>

<xsl:template match="li[@outputclass='lt1']">
    <item><para>
      <xsl:apply-templates/>
    </para></item>
  </xsl:template>

  <xsl:template match="li[@outputclass='lt2']">
    <item><para>
      <xsl:apply-templates/>
    </para></item>
  </xsl:template>

  <xsl:template match="li[@outputclass='lt3']">
    <item><para>
      <xsl:apply-templates/>
    </para></item>
  </xsl:template>

输出我在sublist列表后的子列表末尾需要关闭para:

<body>
<para>blahblah</para>
<itemizedlist type="&#x2022;">
<item><para>blahblah</para></item>
<item><para>blahblah</para></item>
<item><para>blahblah
  <itemizedlist type="&#x2022;">
  <item><para>blahblah</para></item>
  <item><para>blahblah<footnote><p>blah</p></footnote></para></item>
  <item><para>blahblah
    <itemizedlist type="&#x2022;">
    <item><para>blahblah<footnote><p>blah</p></footnote></para></item>
    <item><para>blahblah</para></item>
    <item><para>blahblah</para></item>
    </itemizedlist></para></item>
  </itemizedlist></para></item>
<item><para>blahblah</para></item>
<item><para>blahblah</para></item>
</itemizedlist>
<para>blahblah</para>
</body>

但需要的输出就像子列表一样,应该在para结束和项目结束之间,如下所示:

<body>
<para>blahblah</para>
<itemizedlist type="&#x2022;">
<item><para>blahblah</para></item>
<item><para>blahblah</para></item>
**<item><para>blahblah</para>**
  <itemizedlist type="&#x2022;">
  <item><para>blahblah</para></item>
  <item><para>blahblah</para></item>
  **<item><para>blahblah<footnote><p>blah</p></footnote></para>**
    <itemizedlist type="&#x2022;">
    <item><para>blahblah<footnote><p>blah</p></footnote></para></item>
    <item><para>blahblah</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>

是否有可能是粗体的。 如果可能请建议我

先谢谢。

1 个答案:

答案 0 :(得分:0)

我认为您只想在apply-templates元素中使用li,然后将任何非空白文本节点包装到para元素中:

<?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="&#x2022;">
            <xsl:apply-templates/>
        </itemizedlist>
    </xsl:template>

    <xsl:template match="ul[@outputclass='l2']">
        <itemizedlist type="&#x2022;">
            <xsl:apply-templates/>
        </itemizedlist>
    </xsl:template>

    <xsl:template match="ul[@outputclass='l3']">
        <itemizedlist type="&#x2022;">
            <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>