Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 如何使用XSLT将Microsoft Word DOCX文件中的嵌套列表转换为HTML?_Xml_Xslt - Fatal编程技术网

Xml 如何使用XSLT将Microsoft Word DOCX文件中的嵌套列表转换为HTML?

Xml 如何使用XSLT将Microsoft Word DOCX文件中的嵌套列表转换为HTML?,xml,xslt,Xml,Xslt,我得到的结果不是这个数字,而是: 1.First Item 2.Second Item 3.Third Item i.Third Item – One ii.Third Item – Two a.Sample Item A b.Sample Item B 4.Fourth Item 这是我在XSLT中的解决方案,通过使用和来解决这个问题,但我想我需要一些不同的东西来实现这里。我不知道该怎么办,其余的都很好,我可以处理表格的各个部分,但是嵌套列表现在有

我得到的结果不是这个数字,而是:

1.First Item
2.Second Item
3.Third Item
    i.Third Item – One
    ii.Third Item – Two
       a.Sample Item A
       b.Sample Item B
4.Fourth Item
这是我在XSLT中的解决方案,通过使用
  • 来解决这个问题,但我想我需要一些不同的东西来实现这里。我不知道该怎么办,其余的都很好,我可以处理表格的各个部分,但是嵌套列表现在有问题了

    •First Item
    •Second Item
    •Third Item
    •Third Item – One
    •Third Item – Two
    •Sample Item A
    •Sample Item B
    •Fourth Item
    
    
    

    *我找到了解决办法*

    <xsl:output method="html" doctype-system="about:legacy-compat"/>
        <xsl:template match="/">
            <html>
                <head>
                    <title/>
                </head>
                <body>
                    <xsl:apply-templates/>
                </body>
            </html>
            </xsl:template>
            <xsl:template match="w:p">
                <xsl:if test="w:pPr/w:pStyle[@w:val='AppBody-Title']">
                    <h1>
                        <xsl:apply-templates select="w:r/w:t"/>
                    </h1>
                </xsl:if>
                <xsl:if test="w:pPr/w:pStyle[@w:val='AppBody-Description']">
                        <xsl:choose>
                            <xsl:when test="w:pPr/w:numPr">
                            <ul>
                                <li><xsl:apply-templates select="w:r/w:t"/></li>
                            </ul>
                            </xsl:when>
                            <xsl:otherwise>
                            <p>
                                <xsl:apply-templates select="w:r/w:t"/>
                            </p>
                            </xsl:otherwise>
                        </xsl:choose>
                </xsl:if>
                <xsl:if test="w:pPr/w:pStyle[@w:val='AppBody-Claim']">
                    <p>
                        <xsl:apply-templates select="w:r/w:t"/>
                    </p>
                </xsl:if>
                <xsl:if test="w:pPr/w:spacing[@w:line='360']">
                    <p>
                        <xsl:apply-templates select="w:r/w:t"/>
                    </p>
                </xsl:if>
                <xsl:if test="w:pPr/w:pStyle[@w:val='AppBody-Heading']">
                    <h2>
                        <xsl:apply-templates select="w:r/w:t"/>
                    </h2>
                </xsl:if>
            </xsl:template>
    </xsl:stylesheet>
    
    
    

    *但这不是一个自动的解决方案。例如,如果在不同的文档中有另一层,这将不起作用


    我们如何自动选择数字“1”到“.”?

    这个问题的答案隐藏在

    但是因为周围有很多噪音,我将提取相关部分

    给定具有级别编号的元素序列:

    <xsl:output method="html" doctype-system="about:legacy-compat"/>
        <xsl:template match="/">
            <html>
                <head>
                    <title/>
                </head>
                <body>
                    <xsl:apply-templates/>
                </body>
            </html>
            </xsl:template>
            <xsl:template match="w:p">
                <xsl:if test="w:pPr/w:pStyle[@w:val='AppBody-Title']">
                    <h1>
                        <xsl:apply-templates select="w:r/w:t"/>
                    </h1>
                </xsl:if>
                <xsl:if test="w:pPr/w:pStyle[@w:val='AppBody-Description']">
                        <xsl:choose>
                            <xsl:when test="w:pPr/w:numPr/w:ilvl[@w:val='1']">
                            <ul>
                                <li><xsl:apply-templates select="w:r/w:t"/></li>
                            </ul>
                            </xsl:when>
                            <xsl:when test="w:pPr/w:numPr/w:ilvl[@w:val='2']">
                            <ul>
                                <ul>
                                    <li><xsl:apply-templates select="w:r/w:t"/></li>
                                </ul>
                            </ul>
                            </xsl:when>
                            <xsl:when test="w:pPr/w:numPr/w:ilvl[@w:val='3']">
                            <ul>
                                <ul>
                                    <ul>
                                        <li><xsl:apply-templates select="w:r/w:t"/></li>
                                    </ul>
                                </ul>
                            </ul>
                            </xsl:when>
                            <xsl:otherwise>
                            <p>
                                <xsl:apply-templates select="w:r/w:t"/>
                            </p>
                            </xsl:otherwise>
                        </xsl:choose>
                </xsl:if>
                <xsl:if test="w:pPr/w:pStyle[@w:val='AppBody-Claim']">
                    <p>
                        <xsl:apply-templates select="w:r/w:t"/>
                    </p>
                </xsl:if>
                <xsl:if test="w:pPr/w:spacing[@w:line='360']">
                    <p>
                        <xsl:apply-templates select="w:r/w:t"/>
                    </p>
                </xsl:if>
                <xsl:if test="w:pPr/w:pStyle[@w:val='AppBody-Heading']">
                    <h2>
                        <xsl:apply-templates select="w:r/w:t"/>
                    </h2>
                </xsl:if>
            </xsl:template>
    </xsl:stylesheet>
    
    
    
    我们可以把它们变成树形结构

    <a level="1"/>
    <b level="2"/>
    <c level="3"/>
    <d level="3"/>
    <e level="2"/>
    
    
    
    使用递归分组,如下所示。我们编写一个模板,进行一级分组,然后递归地调用自己进行下一级分组:

    <a><b><c/><d/></b><e/></a>
    
    
    
    这是在使用XSLT2.0。使用XSLT1.0的解决方案将非常非常困难


    当然,与我的小样本相比,您的输入有很多M$噪音。但是问题的结构是一样的。

    谢谢你的回答,我将尝试在我的代码中使用这个方法,让我们看看它是否有效。顺便问一下,你为什么认为这里有很多噪音?不是“这里”,而是“那里”-在链接到的地方。
    <a><b><c/><d/></b><e/></a>
    
    <xsl:template name="grouping">
      <xsl:param name="input" as="element()*"/>
      <xsl:if test="exists($input)">
        <xsl:variable name="level" select="$input[1]/@level"/>
        <xsl:for-each-group select="$input" 
                            group-starting-with="*[@level=$level]">
          <xsl:copy>
            <xsl:call-template name="grouping">
               <xsl:with-param name="input" 
                               select="current-group()[position() gt 1]"/>
            </xsl:call-template>
          </xsl:copy>
        </xsl:for-each-group>
      </xsl:if>
    </xsl:template>