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

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
Xml 使用XSLT替换部分非结构化数据中的标记_Xml_Xslt - Fatal编程技术网

Xml 使用XSLT替换部分非结构化数据中的标记

Xml 使用XSLT替换部分非结构化数据中的标记,xml,xslt,Xml,Xslt,在下面的示例中,我想用替换标记,或者至少返回所有文本(包括s),以便用Javascript替换s XML: 这是一个错误的观点。 编辑: 我也只想返回第2项的结果,完全忽略第1项。一个非常小的值就可以了。 这里唯一的“诀窍”是考虑命名空间。 试试这个: <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Trans

在下面的示例中,我想用

替换
标记,或者至少返回所有文本(包括
s),以便用Javascript替换
s

XML:


这是一个错误的观点。
编辑: 我也只想返回第2项的结果,完全忽略第1项。

一个非常小的值就可以了。
这里唯一的“诀窍”是考虑命名空间。 试试这个:

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

                 exclude-result-prefixes='dxl'  >
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="dxl:break">
        <br>
            <xsl:apply-templates select="@*|node()"/>
        <br >
    </xsl:template>

</xsl:stylesheet>



将生成以下输出:

<?xml version="1.0"?>
<document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.lotus.com/dxl" xsi:schemaLocation="http://www.lotus.com/dxl xmlschemas/domino_8_5_3.xsd">

    <item name="item1">
        <textlist>
            <text/>
        </textlist>
    </item>
    <item name="item2">
        <textlist>
            <text>
                This<br/>is<br/>a<br/>broken<br/>sentence.<br/>
            </text>
        </textlist>
    </item>
</document>

这是一个破碎的句子
更新附加问题以忽略“项目1” 将以下行添加到样式表:

<xsl:template match ="dxl:item[@name='item1']" />

或者,如果输出中应该只有“item2”,请添加根模板:

<xsl:template match="/">
    <document>
        <xsl:apply-templates select="*/dxl:item[@name='item2']" />
    </document>
</xsl:template>


谢谢,这很有效。我在我的原始帖子中省略了我的部分标准。你能帮我解决编辑问题吗?@NickBetcher;谢谢你的修复。但我建议继续使用开头-结尾

,因为如果
中没有内容,它将生成一个标准。但是,使用单个br>的模板如果break中有内容,则将引发异常。如果希望始终使用单个br,则还应删除apply tmeplates form break模板
<xsl:template match="/">
    <document>
        <xsl:apply-templates select="*/dxl:item[@name='item2']" />
    </document>
</xsl:template>