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
XSLT-需要帮助标记文本吗_Xslt - Fatal编程技术网

XSLT-需要帮助标记文本吗

XSLT-需要帮助标记文本吗,xslt,Xslt,在下面的示例中,我需要在bulletlist结束标记和para结束标记之间出现的文本周围插入一个“缩进”标记 <para>Blah, blah, blah-blah, blah, blah, blah, blah<emphasis type="q">BL</emphasis>. </para> <para>TheBlah, blah, blah-blah, blah, blah, blah, blah is created using

在下面的示例中,我需要在bulletlist结束标记和para结束标记之间出现的文本周围插入一个“缩进”标记

<para>Blah, blah, blah-blah, blah, blah, blah, blah<emphasis type="q">BL</emphasis>. </para>
<para>TheBlah, blah, blah-blah, blah, blah, blah, blah is created using the following schema:<bulletlist>
<li>First two letters. </li>
<li>Next four digits.</li>
<li>Next three digits.</li>
<li>Final six digits.</li>
</bulletlist>Here is the text I need to capture and place in an "indet" tag.</para>
废话,废话,废话,废话,废话,废话,废话。 诸如此类诸如此类诸如此类,诸如此类诸如此类,诸如此类,诸如此类,诸如此类是使用以下模式创建的:
  • 前两个字母
  • 接下来的四位数
  • 接下来的三位数
  • 最后六位数
  • 下面是我需要捕获并放置在“indet”标记中的文本。 在XSLT中如何处理这个问题?我对这门语言不熟悉,有点沮丧

    我还需要标记numlist结束标记、alphalist结束标记、note结束标记和table结束标记后面的文本,这些标记出现在带有“indent标记”的para中。例子如下:

    <para>Blah, blah, blah-blah, blah, blah, blah, blah<emphasis type="q">BL</emphasis>. </para>
    <para>TheBlah, blah, blah-blah, blah, blah, blah, blah is created using the following schema:<numlist>
    <li>First two letters. </li>
    <li>Next four digits.</li>
    <li>Next three digits.</li>
    <li>Final six digits.</li>
    </numlist>Here is the text I need to capture and place in an "indet" tag.</para>
    
    <para>Blah, blah, blah-blah, blah, blah, blah, blah<emphasis type="q">BL</emphasis>. </para>
    <para>The Blah, blah, blah-blah, blah, blah, blah, blah is created using the following schema:<numlist>
    <li>First two letters. </li>
    <li>Next four digits.</li>
    <li>Next three digits.</li>
    <li>Final six digits.</li>
    </numlist>Here is the text I need to capture and place in an "indent" tag.</para>
    
    <para>Blah, blah, blah-blah, blah, blah, blah, blah<emphasis type="q">BL</emphasis>. </para>
    <para>The Blah, blah, blah-blah, blah, blah, blah, blah is created using the following schema:<note>
    Blah, blah, blah, blah . . . 
    </note>Here is the text I need to capture and place in an "indent" tag.</para>
    
    <para>Blah, blah, blah-blah, blah, blah, blah, blah<emphasis type="q">BL</emphasis>. </para>
    <para>The Blah, blah, blah-blah, blah, blah, blah, blah is created using the following schema:<table><tgroup cols="3" colsep="1" rowsep="3">
    <colspec colname="col1" colwidth="25*"/>
    <colspec colname="col2" colwidth="36*"/>
    <colspec colname="col3" colwidth="39*"/>
    <thead>
    <row>
    <entry align="center" valign="top"><emphasis type="b">Sub-status Code </emphasis></entry>
    <entry align="center" valign="top"><emphasis type="b"> Sub-status Code Name</emphasis></entry>
    <entry align="center" valign="top"><emphasis type="b">Description</emphasis></entry>
    </row>
    </thead>
    <tbody>
    <row>
    <entry align="center" colsep="1" rowsep="1">AC</entry>
    <entry colsep="1" rowsep="1">Auto Closure</entry>
    <entry colsep="1" rowsep="1">Automatic closed></entry>
    </row>
    </tbody>
    </tgroup>
    </table>Here is the text I need to capture and place in an "indet" tag.</para>
    
    废话,废话,废话,废话,废话,废话,废话。 诸如此类诸如此类诸如此类,诸如此类诸如此类,诸如此类,诸如此类,诸如此类是使用以下模式创建的:
  • 前两个字母
  • 接下来的四位数
  • 接下来的三位数
  • 最后六位数
  • 下面是我需要捕获并放置在“indet”标记中的文本。 废话废话废话废话废话废话废话。 诸如此类,诸如此类,诸如此类,诸如此类,诸如此类,诸如此类是使用以下模式创建的:
  • 前两个字母
  • 接下来的四位数
  • 接下来的三位数
  • 最后六位数
  • 下面是我需要捕获并放置在“缩进”标记中的文本。 废话废话废话废话废话废话废话。 诸如此类,诸如此类,诸如此类,诸如此类,诸如此类,诸如此类是使用以下模式创建的: 废话,废话,废话,废话。 下面是我需要捕获并放置在“缩进”标记中的文本。 废话废话废话废话废话废话废话。 诸如此类,诸如此类,诸如此类,诸如此类,诸如此类,诸如此类是使用以下模式创建的: 子状态代码 子状态代码名 描述 自动控制 自动关闭 自动关闭> 下面是我需要捕获并放置在“indet”标记中的文本。 谁能提出建议

    我已经尝试了几天,但都没有成功。下面是我最近的一次尝试:

    <?xml version="1.0" encoding="UTF-8"?> 
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    
    <xsl:template match="@* | node()"> 
    <xsl:copy> 
    <xsl:apply-templates select="node()"/> 
    </xsl:copy> 
    </xsl:template>
    
    <xsl:template match="para-wrap/text()[following-sibling::bulletlist | alphalist | numlist | note | table]">
    <indent> 
    <xsl:value-of select="."/> 
    </indent> 
    </xsl:template>  
    </xsl:stylesheet>
    

    您的意思是,如果它是
    para
    的子元素,并且是
    bulletlist
    note
    等的紧跟兄弟元素,只需在
    缩进
    元素中放置一个文本节点即可吗?然后,下面的样式表生成正确的输出

    既然您提到了元素的“结束标记”,那么让我为您澄清一下:XSLT处理器查看XML文档的方式与您查看XML文档的方式不同。更准确地说,处理器可以看到它的解析版本,以树的形式(称为XDM)。在这个树中,根本没有标记,既没有开始标记,也没有结束标记。所有项目都简单地表示为节点

    因此,要求XSLT样式表考虑元素的结束标记是错误的。您的问题必须解释为:查找紧跟在
    bulletlist
    元素后面作为其同级元素的文本节点

    样式表

    <?xml version="1.0" encoding="UTF-8" ?>
    <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
        <xsl:output method="xml" encoding="UTF-8" indent="yes" />
    
        <xsl:strip-space elements="*"/>
    
        <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:template>
    
        <xsl:template match="para/text()">
    
            <xsl:choose>
                <xsl:when test="preceding-sibling::*[1][name() = 'bulletlist' or name() = 'alphalist' or name() = 'numlist' or name() = 'table' or name() = 'note']">
                    <indent>
                        <xsl:value-of select="."/>
                    </indent>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:copy/>
                </xsl:otherwise>
            </xsl:choose>
    
        </xsl:template>
    </xsl:transform>
    
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
    <para>Blah, blah, blah-blah, blah, blah, blah, blah<emphasis type="q">BL</emphasis>. </para>
    <para>TheBlah, blah, blah-blah, blah, blah, blah, blah is created using the following schema:<bulletlist>
    <li>First two letters. </li>
    <li>Next four digits.</li>
    <li>Next three digits.</li>
    <li>Final six digits.</li>
    </bulletlist>Here is the text I need to capture and place in an "indet" tag.</para>
    </root>
    
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
       <para>Blah, blah, blah-blah, blah, blah, blah, blah<emphasis type="q">BL</emphasis>. </para>
       <para>TheBlah, blah, blah-blah, blah, blah, blah, blah is created using the following schema:<bulletlist>
             <li>First two letters. </li>
             <li>Next four digits.</li>
             <li>Next three digits.</li>
             <li>Final six digits.</li>
          </bulletlist>
          <indent>Here is the text I need to capture and place in an "indet" tag.</indent>
       </para>
    </root>
    
    
    
    应用于以下输入:

    XML输入

    <?xml version="1.0" encoding="UTF-8" ?>
    <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
        <xsl:output method="xml" encoding="UTF-8" indent="yes" />
    
        <xsl:strip-space elements="*"/>
    
        <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:template>
    
        <xsl:template match="para/text()">
    
            <xsl:choose>
                <xsl:when test="preceding-sibling::*[1][name() = 'bulletlist' or name() = 'alphalist' or name() = 'numlist' or name() = 'table' or name() = 'note']">
                    <indent>
                        <xsl:value-of select="."/>
                    </indent>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:copy/>
                </xsl:otherwise>
            </xsl:choose>
    
        </xsl:template>
    </xsl:transform>
    
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
    <para>Blah, blah, blah-blah, blah, blah, blah, blah<emphasis type="q">BL</emphasis>. </para>
    <para>TheBlah, blah, blah-blah, blah, blah, blah, blah is created using the following schema:<bulletlist>
    <li>First two letters. </li>
    <li>Next four digits.</li>
    <li>Next three digits.</li>
    <li>Final six digits.</li>
    </bulletlist>Here is the text I need to capture and place in an "indet" tag.</para>
    </root>
    
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
       <para>Blah, blah, blah-blah, blah, blah, blah, blah<emphasis type="q">BL</emphasis>. </para>
       <para>TheBlah, blah, blah-blah, blah, blah, blah, blah is created using the following schema:<bulletlist>
             <li>First two letters. </li>
             <li>Next four digits.</li>
             <li>Next three digits.</li>
             <li>Final six digits.</li>
          </bulletlist>
          <indent>Here is the text I need to capture and place in an "indet" tag.</indent>
       </para>
    </root>
    
    
    废话废话废话废话废话废话废话。
    诸如此类诸如此类诸如此类,诸如此类诸如此类,诸如此类,诸如此类,诸如此类是使用以下模式创建的:
    
  • 前两个字母
  • 接下来的四位数
  • 接下来的三位数
  • 最后六位数
  • 下面是我需要捕获并放置在“indet”标记中的文本。
    XML输出

    <?xml version="1.0" encoding="UTF-8" ?>
    <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
        <xsl:output method="xml" encoding="UTF-8" indent="yes" />
    
        <xsl:strip-space elements="*"/>
    
        <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:template>
    
        <xsl:template match="para/text()">
    
            <xsl:choose>
                <xsl:when test="preceding-sibling::*[1][name() = 'bulletlist' or name() = 'alphalist' or name() = 'numlist' or name() = 'table' or name() = 'note']">
                    <indent>
                        <xsl:value-of select="."/>
                    </indent>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:copy/>
                </xsl:otherwise>
            </xsl:choose>
    
        </xsl:template>
    </xsl:transform>
    
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
    <para>Blah, blah, blah-blah, blah, blah, blah, blah<emphasis type="q">BL</emphasis>. </para>
    <para>TheBlah, blah, blah-blah, blah, blah, blah, blah is created using the following schema:<bulletlist>
    <li>First two letters. </li>
    <li>Next four digits.</li>
    <li>Next three digits.</li>
    <li>Final six digits.</li>
    </bulletlist>Here is the text I need to capture and place in an "indet" tag.</para>
    </root>
    
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
       <para>Blah, blah, blah-blah, blah, blah, blah, blah<emphasis type="q">BL</emphasis>. </para>
       <para>TheBlah, blah, blah-blah, blah, blah, blah, blah is created using the following schema:<bulletlist>
             <li>First two letters. </li>
             <li>Next four digits.</li>
             <li>Next three digits.</li>
             <li>Final six digits.</li>
          </bulletlist>
          <indent>Here is the text I need to capture and place in an "indet" tag.</indent>
       </para>
    </root>
    
    
    废话废话废话废话废话废话废话。
    诸如此类诸如此类诸如此类,诸如此类诸如此类,诸如此类,诸如此类,诸如此类是使用以下模式创建的:
    
  • 前两个字母
  • 接下来的四位数
  • 接下来的三位数
  • 最后六位数
  • 下面是我需要捕获并放置在“indet”标记中的文本。
    我不明白你的问题。请澄清什么是输入示例,以及预期输出是什么(每个示例,如果您有几个示例)。是的,这就是我的意思。谢谢你帮我澄清。我急于尝试代码@TracyStahl您只需单击此按钮即可尝试该代码。如果你发现答案是有用的,我可以请你考虑接受我的回答吗?谢谢你的帮助@马蒂亚斯穆勒。我一直在尝试实现,但是,代码没有在我的完整文档中工作,我不知道为什么。