维护嵌套元素的分组方法 XSLT 2.0 - 分离多余的

发布于 2024-11-01 19:46:35 字数 13289 浏览 5 评论 0原文

我将项目符号项目进行分组,并将它们作为项目符号项目的第二个列表嵌入到某些列表元素中。我可以将项目分组,但我的递归模板正在选择从文档中当前位置到末尾的所有内容。我需要为嵌套列表设置一个终点。

我的输出看起来像这样:

<ul>
    <li>First Bullet:<ul>
         <li>Sub-bullet 1: info for sub-bullet
                                            1</li>
         <li>Sub-bullet 2: info for sub-bullet
                                            2</li>
         <li>Sub-bullet 3: info for sub-bullet
                                            3</li>
         <li>Sub-bullet 4: info for sub-bullet
                                                4</li>
         <li>Sub-bullet 5: info for sub-bullet
                                            5</li>
         <li>Sub-bullet 6: info for sub-bullet
                                            6</li>
        </ul>
    </li>

    <li>Second Bullet:<ul>
         <li>Sub-bullet 5: info for sub-bullet
                                            5</li>
         <li>Sub-bullet 6: info for sub-bullet
                                            6</li>
        </ul>
    </li>
</ul>

但它应该看起来像这样(第一个 li 下没有子项目符号 5 和 6):

<ul>
    <li>First Bullet:<ul>
         <li>Sub-bullet 1: info for sub-bullet
                                            1</li>
         <li>Sub-bullet 2: info for sub-bullet
                                            2</li>
         <li>Sub-bullet 3: info for sub-bullet
                                            3</li>
         <li>Sub-bullet 4: info for sub-bullet
                                                4</li>
        </ul>
    </li>

    <li>Second Bullet:<ul>
         <li>Sub-bullet 5: info for sub-bullet
                                            5</li>
         <li>Sub-bullet 6: info for sub-bullet
                                            6</li>
        </ul>
    </li>
</ul>

我不确定如何正确地将 XSLT 中的子项目符号分组以使它们处于正确的位置。

这是我的来源:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<office:document-content xmlns:dom="http://www.w3.org/2001/xml-events"
  xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
  xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
  xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"
  xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
  xmlns:smil="urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0"
  xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
  xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
  xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
  xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
  xmlns:xlink="http://www.w3.org/1999/xlink"
  xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0">
  <office:body>
    <office:presentation>
      <draw:page draw:name="Slide1" draw:style-name="a1271"
        draw:master-page-name="Master1-Layout3-cust-Bullet"
        presentation:presentation-page-layout-name="Master1-PPL3">
        <draw:frame draw:id="id109" presentation:style-name="a1039"
                    draw:name="Content Placeholder 1" svg:x="0.31258in" svg:y="1.29095in"
                    svg:width="9.33243in" svg:height="3.8175in" presentation:class="outline"
                    presentation:placeholder="false">
                    <draw:text-box>
                        <text:list text:style-name="a1012">
                            <text:list-item>
                                <text:p text:style-name="a1011" text:class-names=""
                                    text:cond-style-name=""><text:span text:style-name="a1010"
                                        text:class-names="">First Bullet:</text:span></text:p>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1015">
                            <text:list-item>
                                <text:list text:style-name="a1015">
                                    <text:list-item>
                                        <text:p text:style-name="a1014" text:class-names=""
                                            text:cond-style-name=""><text:span
                                                text:style-name="a1013" text:class-names=""
                                                >Sub-bullet 1: info for sub-bullet
                                            1</text:span></text:p>
                                    </text:list-item>
                                </text:list>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1018">
                            <text:list-item>
                                <text:list text:style-name="a1018">
                                    <text:list-item>
                                        <text:p text:style-name="a1017" text:class-names=""
                                            text:cond-style-name=""><text:span
                                                text:style-name="a1016" text:class-names=""
                                                >Sub-bullet 2: info for sub-bullet
                                            2</text:span></text:p>
                                    </text:list-item>
                                </text:list>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1021">
                            <text:list-item>
                                <text:list text:style-name="a1021">
                                    <text:list-item>
                                        <text:p text:style-name="a1020" text:class-names=""
                                            text:cond-style-name=""><text:span
                                                text:style-name="a1019" text:class-names=""
                                                >Sub-bullet 3: info for sub-bullet
                                            3</text:span></text:p>
                                    </text:list-item>
                                </text:list>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1025">
                            <text:list-item>
                                <text:list text:style-name="a1025">
                                    <text:list-item>
                                        <text:p text:style-name="a1024" text:class-names=""
                                            text:cond-style-name=""><text:span
                                                text:style-name="a1022" text:class-names=""
                                                >Sub-bullet 4: info for sub-bullet
                                                4</text:span><text:span text:style-name="a1023"
                                                text:class-names=""/></text:p>
                                    </text:list-item>
                                </text:list>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1029">
                            <text:list-item>
                                <text:p text:style-name="a1028" text:class-names=""
                                    text:cond-style-name=""><text:span text:style-name="a1026"
                                        text:class-names="">Second Bullet:</text:span><text:span
                                        text:style-name="a1027" text:class-names=""/></text:p>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1032">
                            <text:list-item>
                                <text:list text:style-name="a1032">
                                    <text:list-item>
                                        <text:p text:style-name="a1031" text:class-names=""
                                            text:cond-style-name=""><text:span
                                                text:style-name="a1030" text:class-names=""
                                                >Sub-bullet 5: info for sub-bullet
                                            5</text:span></text:p>
                                    </text:list-item>
                                </text:list>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1035">
                            <text:list-item>
                                <text:list text:style-name="a1035">
                                    <text:list-item>
                                        <text:p text:style-name="a1034" text:class-names=""
                                            text:cond-style-name=""><text:span
                                                text:style-name="a1033" text:class-names=""
                                                >Sub-bullet 6: info for sub-bullet
                                            6</text:span></text:p>
                                    </text:list-item>
                                </text:list>
                            </text:list-item>
                        </text:list>
                    </draw:text-box>
                    <svg:desc/>
                </draw:frame>
      </draw:page>
    </office:presentation>
  </office:body>
</office:document-content>

这是我的样式表:

<xsl:stylesheet
    version="2.0"
    xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
    xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
    xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
    xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
    xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" 
    xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
    xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
    xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
    xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
    xmlns:math="http://www.w3.org/1998/Math/MathML"
    xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
    xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
    xmlns:dom="http://www.w3.org/2001/xml-events"
    xmlns:xforms="http://www.w3.org/2002/xforms"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"
    office:class="text"
    office:version="1.0"
    exclude-result-prefixes="#all">
    <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>

<xsl:template match="draw:frame">
<ul>
 <xsl:for-each-group select="draw:text-box/text:list" group-starting-with="text:list-item">
  <xsl:for-each select="current-group()">

        <xsl:apply-templates select="text:list-item[not(text:list)]"/>

    </xsl:for-each>
</xsl:for-each-group> 
</ul>
</xsl:template>

<xsl:template match="draw:text-box/text:list/text:list-item/text:list/text:list-item/text:p">
<li><xsl:value-of select="."/></li>
</xsl:template>


<xsl:template match="draw:text-box/text:list/text:list-item/text:p">
<li><xsl:value-of select="."/>
    <!-- Check for nested list -->
    <xsl:if test="../../following-sibling::text:list[text:list-item/text:list]">

            <xsl:for-each select="current-group()">
            <xsl:apply-templates select="text:list-item/text:p"/>
            </xsl:for-each>

            </xsl:for-each-group>
    </ul>
    </xsl:if>
</li>
</xsl:template>


</xsl:stylesheet>

关于如何在 2.0 中实现此目的有什么建议吗?我尝试创建一些计数变量,但在当前组上下文之外建立端点方面还没有任何运气。我知道必须有一种明显的(而且更优雅的)方法来完成这项工作。

I'm grouping bulleted items and embedding them as a second list of bulleted items inside some list elements. I can get the items to group, but my recursion template is selecting everything from my current position in the doc to the end. I need to set an ending point for my nested lists.

My output looks like this:

<ul>
    <li>First Bullet:<ul>
         <li>Sub-bullet 1: info for sub-bullet
                                            1</li>
         <li>Sub-bullet 2: info for sub-bullet
                                            2</li>
         <li>Sub-bullet 3: info for sub-bullet
                                            3</li>
         <li>Sub-bullet 4: info for sub-bullet
                                                4</li>
         <li>Sub-bullet 5: info for sub-bullet
                                            5</li>
         <li>Sub-bullet 6: info for sub-bullet
                                            6</li>
        </ul>
    </li>

    <li>Second Bullet:<ul>
         <li>Sub-bullet 5: info for sub-bullet
                                            5</li>
         <li>Sub-bullet 6: info for sub-bullet
                                            6</li>
        </ul>
    </li>
</ul>

But it SHOULD look like this (without Sub-bullets 5 and 6 under the first li):

<ul>
    <li>First Bullet:<ul>
         <li>Sub-bullet 1: info for sub-bullet
                                            1</li>
         <li>Sub-bullet 2: info for sub-bullet
                                            2</li>
         <li>Sub-bullet 3: info for sub-bullet
                                            3</li>
         <li>Sub-bullet 4: info for sub-bullet
                                                4</li>
        </ul>
    </li>

    <li>Second Bullet:<ul>
         <li>Sub-bullet 5: info for sub-bullet
                                            5</li>
         <li>Sub-bullet 6: info for sub-bullet
                                            6</li>
        </ul>
    </li>
</ul>

I'm not sure how to properly group the sub-bullets in XSLT to get them in the correct position.

Here's my source:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<office:document-content xmlns:dom="http://www.w3.org/2001/xml-events"
  xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
  xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
  xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"
  xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
  xmlns:smil="urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0"
  xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
  xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
  xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
  xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
  xmlns:xlink="http://www.w3.org/1999/xlink"
  xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0">
  <office:body>
    <office:presentation>
      <draw:page draw:name="Slide1" draw:style-name="a1271"
        draw:master-page-name="Master1-Layout3-cust-Bullet"
        presentation:presentation-page-layout-name="Master1-PPL3">
        <draw:frame draw:id="id109" presentation:style-name="a1039"
                    draw:name="Content Placeholder 1" svg:x="0.31258in" svg:y="1.29095in"
                    svg:width="9.33243in" svg:height="3.8175in" presentation:class="outline"
                    presentation:placeholder="false">
                    <draw:text-box>
                        <text:list text:style-name="a1012">
                            <text:list-item>
                                <text:p text:style-name="a1011" text:class-names=""
                                    text:cond-style-name=""><text:span text:style-name="a1010"
                                        text:class-names="">First Bullet:</text:span></text:p>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1015">
                            <text:list-item>
                                <text:list text:style-name="a1015">
                                    <text:list-item>
                                        <text:p text:style-name="a1014" text:class-names=""
                                            text:cond-style-name=""><text:span
                                                text:style-name="a1013" text:class-names=""
                                                >Sub-bullet 1: info for sub-bullet
                                            1</text:span></text:p>
                                    </text:list-item>
                                </text:list>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1018">
                            <text:list-item>
                                <text:list text:style-name="a1018">
                                    <text:list-item>
                                        <text:p text:style-name="a1017" text:class-names=""
                                            text:cond-style-name=""><text:span
                                                text:style-name="a1016" text:class-names=""
                                                >Sub-bullet 2: info for sub-bullet
                                            2</text:span></text:p>
                                    </text:list-item>
                                </text:list>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1021">
                            <text:list-item>
                                <text:list text:style-name="a1021">
                                    <text:list-item>
                                        <text:p text:style-name="a1020" text:class-names=""
                                            text:cond-style-name=""><text:span
                                                text:style-name="a1019" text:class-names=""
                                                >Sub-bullet 3: info for sub-bullet
                                            3</text:span></text:p>
                                    </text:list-item>
                                </text:list>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1025">
                            <text:list-item>
                                <text:list text:style-name="a1025">
                                    <text:list-item>
                                        <text:p text:style-name="a1024" text:class-names=""
                                            text:cond-style-name=""><text:span
                                                text:style-name="a1022" text:class-names=""
                                                >Sub-bullet 4: info for sub-bullet
                                                4</text:span><text:span text:style-name="a1023"
                                                text:class-names=""/></text:p>
                                    </text:list-item>
                                </text:list>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1029">
                            <text:list-item>
                                <text:p text:style-name="a1028" text:class-names=""
                                    text:cond-style-name=""><text:span text:style-name="a1026"
                                        text:class-names="">Second Bullet:</text:span><text:span
                                        text:style-name="a1027" text:class-names=""/></text:p>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1032">
                            <text:list-item>
                                <text:list text:style-name="a1032">
                                    <text:list-item>
                                        <text:p text:style-name="a1031" text:class-names=""
                                            text:cond-style-name=""><text:span
                                                text:style-name="a1030" text:class-names=""
                                                >Sub-bullet 5: info for sub-bullet
                                            5</text:span></text:p>
                                    </text:list-item>
                                </text:list>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1035">
                            <text:list-item>
                                <text:list text:style-name="a1035">
                                    <text:list-item>
                                        <text:p text:style-name="a1034" text:class-names=""
                                            text:cond-style-name=""><text:span
                                                text:style-name="a1033" text:class-names=""
                                                >Sub-bullet 6: info for sub-bullet
                                            6</text:span></text:p>
                                    </text:list-item>
                                </text:list>
                            </text:list-item>
                        </text:list>
                    </draw:text-box>
                    <svg:desc/>
                </draw:frame>
      </draw:page>
    </office:presentation>
  </office:body>
</office:document-content>

Here's my stylesheet:

<xsl:stylesheet
    version="2.0"
    xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
    xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
    xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
    xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
    xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" 
    xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
    xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
    xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
    xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
    xmlns:math="http://www.w3.org/1998/Math/MathML"
    xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
    xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
    xmlns:dom="http://www.w3.org/2001/xml-events"
    xmlns:xforms="http://www.w3.org/2002/xforms"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"
    office:class="text"
    office:version="1.0"
    exclude-result-prefixes="#all">
    <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>

<xsl:template match="draw:frame">
<ul>
 <xsl:for-each-group select="draw:text-box/text:list" group-starting-with="text:list-item">
  <xsl:for-each select="current-group()">

        <xsl:apply-templates select="text:list-item[not(text:list)]"/>

    </xsl:for-each>
</xsl:for-each-group> 
</ul>
</xsl:template>

<xsl:template match="draw:text-box/text:list/text:list-item/text:list/text:list-item/text:p">
<li><xsl:value-of select="."/></li>
</xsl:template>


<xsl:template match="draw:text-box/text:list/text:list-item/text:p">
<li><xsl:value-of select="."/>
    <!-- Check for nested list -->
    <xsl:if test="../../following-sibling::text:list[text:list-item/text:list]">

            <xsl:for-each select="current-group()">
            <xsl:apply-templates select="text:list-item/text:p"/>
            </xsl:for-each>

            </xsl:for-each-group>
    </ul>
    </xsl:if>
</li>
</xsl:template>


</xsl:stylesheet>

Any suggestions on how to accomplish this in 2.0? I've attempted to create some count variables, but haven't had any luck yet on establishing an endpoint outside of the current-group context. I know there must be an obvious (and more elegant) way to get this done.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

殊姿 2024-11-08 19:46:35

有一个简短、简单且容易的解决方案,根本不需要 XSLT 2.0:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
 exclude-result-prefixes="text"
 >
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:template match="text:list">
  <ul><xsl:apply-templates/></ul>
 </xsl:template>

 <xsl:template match="text:list-item[not(text:list)]">
  <li><xsl:apply-templates/></li>
 </xsl:template>

 <xsl:template match=
  "text()[not(ancestor::text:list-item)]"/>
</xsl:stylesheet>

当此转换应用于提供的 XML 文档时:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<office:document-content xmlns:dom="http://www.w3.org/2001/xml-events"
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
xmlns:smil="urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0"
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"   xmlns:xlink="http://www.w3.org/1999/xlink"   xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0">
    <office:body>
        <office:presentation>
            <draw:page draw:name="Slide1" draw:style-name="a1271"         draw:master-page-name="Master1-Layout3-cust-Bullet"         presentation:presentation-page-layout-name="Master1-PPL3">
                <draw:frame draw:id="id109" presentation:style-name="a1039"                     draw:name="Content Placeholder 1" svg:x="0.31258in" svg:y="1.29095in"                     svg:width="9.33243in" svg:height="3.8175in" presentation:class="outline"                     presentation:placeholder="false">
                    <draw:text-box>
                        <text:list text:style-name="a1012">
                            <text:list-item>
                                <text:p text:style-name="a1011" text:class-names=""                                     text:cond-style-name="">
                                    <text:span text:style-name="a1010"                                         text:class-names="">First Bullet:</text:span>
                                </text:p>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1015">
                            <text:list-item>
                                <text:list text:style-name="a1015">
                                    <text:list-item>
                                        <text:p text:style-name="a1014" text:class-names=""                                             text:cond-style-name="">
                                            <text:span                                                 text:style-name="a1013" text:class-names=""                                                 >Sub-bullet 1: info for sub-bullet                                             1</text:span>
                                        </text:p>
                                    </text:list-item>
                                </text:list>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1018">
                            <text:list-item>
                                <text:list text:style-name="a1018">
                                    <text:list-item>
                                        <text:p text:style-name="a1017" text:class-names=""                                             text:cond-style-name="">
                                            <text:span                                                 text:style-name="a1016" text:class-names=""                                                 >Sub-bullet 2: info for sub-bullet                                             2</text:span>
                                        </text:p>
                                    </text:list-item>
                                </text:list>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1021">
                            <text:list-item>
                                <text:list text:style-name="a1021">
                                    <text:list-item>
                                        <text:p text:style-name="a1020" text:class-names=""                                             text:cond-style-name="">
                                            <text:span                                                 text:style-name="a1019" text:class-names=""                                                 >Sub-bullet 3: info for sub-bullet                                             3</text:span>
                                        </text:p>
                                    </text:list-item>
                                </text:list>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1025">
                            <text:list-item>
                                <text:list text:style-name="a1025">
                                    <text:list-item>
                                        <text:p text:style-name="a1024" text:class-names=""                                             text:cond-style-name="">
                                            <text:span                                                 text:style-name="a1022" text:class-names=""                                                 >Sub-bullet 4: info for sub-bullet                                                 4</text:span>
                                            <text:span text:style-name="a1023"                                                 text:class-names=""/>
                                        </text:p>
                                    </text:list-item>
                                </text:list>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1029">
                            <text:list-item>
                                <text:p text:style-name="a1028" text:class-names=""                                     text:cond-style-name="">
                                    <text:span text:style-name="a1026"                                         text:class-names="">Second Bullet:</text:span>
                                    <text:span                                         text:style-name="a1027" text:class-names=""/>
                                </text:p>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1032">
                            <text:list-item>
                                <text:list text:style-name="a1032">
                                    <text:list-item>
                                        <text:p text:style-name="a1031" text:class-names=""                                             text:cond-style-name="">
                                            <text:span                                                 text:style-name="a1030" text:class-names=""                                                 >Sub-bullet 5: info for sub-bullet                                             5</text:span>
                                        </text:p>
                                    </text:list-item>
                                </text:list>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1035">
                            <text:list-item>
                                <text:list text:style-name="a1035">
                                    <text:list-item>
                                        <text:p text:style-name="a1034" text:class-names=""                                             text:cond-style-name="">
                                            <text:span                                                 text:style-name="a1033" text:class-names=""                                                 >Sub-bullet 6: info for sub-bullet                                             6</text:span>
                                        </text:p>
                                    </text:list-item>
                                </text:list>
                            </text:list-item>
                        </text:list>
                    </draw:text-box>
                    <svg:desc/>
                </draw:frame>
            </draw:page>
        </office:presentation>
    </office:body>
</office:document-content>

生成所需的正确结果

<ul>
   <li>First Bullet:</li>
</ul>
<ul>
   <ul>
      <li>Sub-bullet 1: info for sub-bullet                                             1</li>
   </ul>
</ul>
<ul>
   <ul>
      <li>Sub-bullet 2: info for sub-bullet                                             2</li>
   </ul>
</ul>
<ul>
   <ul>
      <li>Sub-bullet 3: info for sub-bullet                                             3</li>
   </ul>
</ul>
<ul>
   <ul>
      <li>Sub-bullet 4: info for sub-bullet                                                 4</li>
   </ul>
</ul>
<ul>
   <li>Second Bullet:</li>
</ul>
<ul>
   <ul>
      <li>Sub-bullet 5: info for sub-bullet                                             5</li>
   </ul>
</ul>
<ul>
   <ul>
      <li>Sub-bullet 6: info for sub-bullet                                             6</li>
   </ul>
</ul>

浏览器显示为

  • 第一个项目符号:
    • 子项目符号 1:子项目符号 1 的信息
    • 子项目符号 2:子项目符号 2 的信息
    • 子项目符号 3:子项目信息项目符号 3
    • 子项目 4:子项目 4 的信息
  • 第二个项目:
    • 子项目 5:子项目 5 的信息 子项目
    • 6:子项目 6 的信息

There is a short, simple and easy solution that doesn't require XSLT 2.0 at all:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
 exclude-result-prefixes="text"
 >
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:template match="text:list">
  <ul><xsl:apply-templates/></ul>
 </xsl:template>

 <xsl:template match="text:list-item[not(text:list)]">
  <li><xsl:apply-templates/></li>
 </xsl:template>

 <xsl:template match=
  "text()[not(ancestor::text:list-item)]"/>
</xsl:stylesheet>

When this transformation is applied on the provided XML document:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<office:document-content xmlns:dom="http://www.w3.org/2001/xml-events"
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
xmlns:smil="urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0"
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"   xmlns:xlink="http://www.w3.org/1999/xlink"   xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0">
    <office:body>
        <office:presentation>
            <draw:page draw:name="Slide1" draw:style-name="a1271"         draw:master-page-name="Master1-Layout3-cust-Bullet"         presentation:presentation-page-layout-name="Master1-PPL3">
                <draw:frame draw:id="id109" presentation:style-name="a1039"                     draw:name="Content Placeholder 1" svg:x="0.31258in" svg:y="1.29095in"                     svg:width="9.33243in" svg:height="3.8175in" presentation:class="outline"                     presentation:placeholder="false">
                    <draw:text-box>
                        <text:list text:style-name="a1012">
                            <text:list-item>
                                <text:p text:style-name="a1011" text:class-names=""                                     text:cond-style-name="">
                                    <text:span text:style-name="a1010"                                         text:class-names="">First Bullet:</text:span>
                                </text:p>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1015">
                            <text:list-item>
                                <text:list text:style-name="a1015">
                                    <text:list-item>
                                        <text:p text:style-name="a1014" text:class-names=""                                             text:cond-style-name="">
                                            <text:span                                                 text:style-name="a1013" text:class-names=""                                                 >Sub-bullet 1: info for sub-bullet                                             1</text:span>
                                        </text:p>
                                    </text:list-item>
                                </text:list>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1018">
                            <text:list-item>
                                <text:list text:style-name="a1018">
                                    <text:list-item>
                                        <text:p text:style-name="a1017" text:class-names=""                                             text:cond-style-name="">
                                            <text:span                                                 text:style-name="a1016" text:class-names=""                                                 >Sub-bullet 2: info for sub-bullet                                             2</text:span>
                                        </text:p>
                                    </text:list-item>
                                </text:list>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1021">
                            <text:list-item>
                                <text:list text:style-name="a1021">
                                    <text:list-item>
                                        <text:p text:style-name="a1020" text:class-names=""                                             text:cond-style-name="">
                                            <text:span                                                 text:style-name="a1019" text:class-names=""                                                 >Sub-bullet 3: info for sub-bullet                                             3</text:span>
                                        </text:p>
                                    </text:list-item>
                                </text:list>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1025">
                            <text:list-item>
                                <text:list text:style-name="a1025">
                                    <text:list-item>
                                        <text:p text:style-name="a1024" text:class-names=""                                             text:cond-style-name="">
                                            <text:span                                                 text:style-name="a1022" text:class-names=""                                                 >Sub-bullet 4: info for sub-bullet                                                 4</text:span>
                                            <text:span text:style-name="a1023"                                                 text:class-names=""/>
                                        </text:p>
                                    </text:list-item>
                                </text:list>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1029">
                            <text:list-item>
                                <text:p text:style-name="a1028" text:class-names=""                                     text:cond-style-name="">
                                    <text:span text:style-name="a1026"                                         text:class-names="">Second Bullet:</text:span>
                                    <text:span                                         text:style-name="a1027" text:class-names=""/>
                                </text:p>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1032">
                            <text:list-item>
                                <text:list text:style-name="a1032">
                                    <text:list-item>
                                        <text:p text:style-name="a1031" text:class-names=""                                             text:cond-style-name="">
                                            <text:span                                                 text:style-name="a1030" text:class-names=""                                                 >Sub-bullet 5: info for sub-bullet                                             5</text:span>
                                        </text:p>
                                    </text:list-item>
                                </text:list>
                            </text:list-item>
                        </text:list>
                        <text:list text:style-name="a1035">
                            <text:list-item>
                                <text:list text:style-name="a1035">
                                    <text:list-item>
                                        <text:p text:style-name="a1034" text:class-names=""                                             text:cond-style-name="">
                                            <text:span                                                 text:style-name="a1033" text:class-names=""                                                 >Sub-bullet 6: info for sub-bullet                                             6</text:span>
                                        </text:p>
                                    </text:list-item>
                                </text:list>
                            </text:list-item>
                        </text:list>
                    </draw:text-box>
                    <svg:desc/>
                </draw:frame>
            </draw:page>
        </office:presentation>
    </office:body>
</office:document-content>

the wanted, correct result is produced:

<ul>
   <li>First Bullet:</li>
</ul>
<ul>
   <ul>
      <li>Sub-bullet 1: info for sub-bullet                                             1</li>
   </ul>
</ul>
<ul>
   <ul>
      <li>Sub-bullet 2: info for sub-bullet                                             2</li>
   </ul>
</ul>
<ul>
   <ul>
      <li>Sub-bullet 3: info for sub-bullet                                             3</li>
   </ul>
</ul>
<ul>
   <ul>
      <li>Sub-bullet 4: info for sub-bullet                                                 4</li>
   </ul>
</ul>
<ul>
   <li>Second Bullet:</li>
</ul>
<ul>
   <ul>
      <li>Sub-bullet 5: info for sub-bullet                                             5</li>
   </ul>
</ul>
<ul>
   <ul>
      <li>Sub-bullet 6: info for sub-bullet                                             6</li>
   </ul>
</ul>

and the browser displays this as:

  • First Bullet:
    • Sub-bullet 1: info for sub-bullet 1
    • Sub-bullet 2: info for sub-bullet 2
    • Sub-bullet 3: info for sub-bullet 3
    • Sub-bullet 4: info for sub-bullet 4
  • Second Bullet:
    • Sub-bullet 5: info for sub-bullet 5
    • Sub-bullet 6: info for sub-bullet 6
羅雙樹 2024-11-08 19:46:35

您需要一个与文本列表匹配的模板;这将输出

    ;标签。

You need a template that matches a text-list; this would output the <ul> tag.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文