Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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 作为列表和子列表格式的段落_Xml_Xslt - Fatal编程技术网

Xml 作为列表和子列表格式的段落

Xml 作为列表和子列表格式的段落,xml,xslt,Xml,Xslt,我想para的列表格式子列表也是para格式的列表格式 我的输入XML文件: <?xml version="1.0" encoding="UTF-8"?> <chapter> <title>Base Food</title> <subsection> <title>Nothing</title> <body> <p> (a)<tab/>1Y The Act also st

我想para的列表格式子列表也是para格式的列表格式

我的输入XML文件:

<?xml version="1.0" encoding="UTF-8"?>


<chapter>
<title>Base Food</title>
<subsection>
<title>Nothing</title>
<body>
<p>  (a)<tab/>1Y The Act also states that the may undertake a review of the definition of the term.</p>
<p>  (b)<tab/>The Act also states that the may undertake a review of the definition of the term:</p>
<p>  (i)<tab/>Act also states that the may undertake a review of the definition of the term.</p>
<p>  (ii)<tab/>States that the may undertake a review of the definition of the term.</p>
</body>
</subsection>
</chapter>

基础食物
没有什么
(a)该法还规定,缔约国可对该术语的定义进行审查

(b)该法还规定,缔约国可对下列用语的定义进行审查:

(i)该法还规定,缔约国可对该词的定义进行审查

二声明缔约国可对该术语的定义进行审查

我的XSLT编码是

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes" omit-xml-declaration="no"></xsl:output>

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


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

<xsl:template match="subsection">
<section>
<xsl:apply-templates/>
</section>
</xsl:template>

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

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

</xsl:stylesheet>


</xsl:stylesheet>

我得到的输出是

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<chapter>
<title>Base Food</title>
<section>
<title>Nothing</title>
<para>  (a)<tab/>1Y The Act also states that the may undertake a review of the definition of the term.</para>
<para>  (b)<tab/>The Act also states that the may undertake a review of the definition of the term:</para>
<para>  (i)<tab/>Act also states that the may undertake a review of the definition of the term.</para>
<para>  (ii)<tab/>States that the may undertake a review of the definition of the term.</para>
</section>
</chapter>

基础食物
没有什么
(a) 该法还规定,缔约国可对该术语的定义进行审查。
(b) 该法还规定,缔约国可对该术语的定义进行审查:
(i) 该法还规定,缔约国可对该术语的定义进行审查。
二声明缔约国可对该术语的定义进行审查。
但我希望输出标签标签在文本之前作为项属性

所需的输出

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<chapter>
<title>Base Food</title>
<section level="sect1" num="I" number-type="manual">
<title>Nothing</title>
<orderedlist type="manual">
<item num="(a)"><para>1Y The Act also states that the may undertake a review of the definition of the term.</para></item>
<item num="(b)"><para>The Act also states that the may undertake a review of the definition of the term:</para>
<orderedlist type="manual">
<item num="(i)"><para>Act also states that the may undertake a review of the definition of the term.</para></item>
<item num="(ii)"><para>States that the may undertake a review of the definition of the term.</para></item></orderedlist></item></orderedlist>
</section>
</chapter>

基础食物
没有什么
该法还规定,缔约国可对该术语的定义进行审查。
该法还规定,缔约国可对该术语的定义进行审查:
该法还规定,缔约国可对该术语的定义进行审查。
缔约国可对该术语的定义进行审查。
请帮助我


提前感谢

这里尝试编写一个模板来匹配
正文
,为每个相邻的组使用
,首先识别相邻的
p
元素,然后使用递归函数为每个组使用
查找嵌套列表,从
开始:

<?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"
    xmlns:math="http://www.w3.org/2005/xpath-functions/math" xmlns:mf="http://example.com/mf"
    exclude-result-prefixes="xs math mf" version="3.0">

    <xsl:param name="patterns" as="xs:string*" select="'^\s*(\(a\))', '^\s*(\(i\))'"/>

    <xsl:output indent="yes"/>

    <xsl:mode on-no-match="shallow-copy"/>

    <xsl:function name="mf:list-group" as="node()*">
        <xsl:param name="input" as="element()*"/>
        <xsl:sequence select="mf:list-group($input, $patterns)"/>
    </xsl:function>

    <xsl:function name="mf:list-group" as="node()*">
        <xsl:param name="input" as="node()*"/>
        <xsl:param name="patterns" as="xs:string*"/>
        <xsl:choose>
            <xsl:when test="$patterns[1]">
                <xsl:for-each-group select="$input"
                    group-starting-with="p[matches(., $patterns[1])]">
                    <xsl:choose>
                        <xsl:when test="self::p[matches(., $patterns[1])]">
                            <orderedlist type="manual">
                                <xsl:sequence select="mf:list-group(current-group(), $patterns[position() gt 1])"></xsl:sequence>
                            </orderedlist>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:apply-templates select="current-group()"/>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:for-each-group>
            </xsl:when>
            <xsl:otherwise>
                <xsl:apply-templates select="$input"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:function>

    <xsl:template match="body">
        <xsl:for-each-group select="*"
            group-adjacent="boolean(self::p[node()[1][self::text()[matches(., '^\s*\([a-z]+\)$')]] and node()[2][self::tab]])">
            <xsl:choose>
                <xsl:when test="current-grouping-key()">
                    <xsl:sequence select="mf:list-group(current-group())"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:apply-templates select="current-group()"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:for-each-group>
    </xsl:template>

    <xsl:template match="p">
        <item num="{replace(node()[1], '^\s+', '')}">
            <para><xsl:apply-templates select="node()[position() gt 2]"/></para>
        </item>
    </xsl:template>
</xsl:stylesheet>


我已经将其编写为Saxon 9.8支持的XSLT 3.0,但是您应该能够将除
之外的所有内容合并到XSLT 2.0样式表中,并使用其他模板进行您已有的转换。

这似乎是一个分组问题(组开始于
a
I
)。谢谢@Martin Honnen