Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.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在XML中搜索元素(如果该元素前面有一个元素)_Xml_Xslt - Fatal编程技术网

通过XSLT在XML中搜索元素(如果该元素前面有一个元素)

通过XSLT在XML中搜索元素(如果该元素前面有一个元素),xml,xslt,Xml,Xslt,我正在研究一个文本,我想通过样式表XSLT获得一个特定的函数(特别是,),前提是它前面有一个句号()。如何在XSLT样式表中设置此条件?我已尝试使用以前的同级:,但它没有返回任何内容。以下是我创建的样式表XSLT和XML: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:t

我正在研究一个文本,我想通过样式表XSLT获得一个特定的函数(特别是,
),前提是它前面有一个句号(
)。如何在XSLT样式表中设置此条件?我已尝试使用以前的同级:,但它没有返回任何内容。以下是我创建的样式表XSLT和XML:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:tei="http://www.tei-c.org/ns/1.0">
    <xsl:output method="html"/>
    <xsl:template match="/">
        <html lang="es">
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
            </head>
            <body>
                <h3 align="center">
                    <b>COORDINADAS ADVERSATIVA</b>
                </h3>
                <table width="750" border="1" align="center">
                    <tr height="150%">
                        <th scope="col" bgcolor="#00CCFF" height="150%">
                            <div align="center">Coordinadas adversativas</div>
                        </th>
                        <th scope="col" bgcolor="#00CCFF" height="150%">
                            <div align="center">Libro</div>
                        </th>
                        <th scope="col" bgcolor="#00CCFF" height="150%">
                            <div align="center">Capítulo</div>
                        </th>
                        <th scope="col" bgcolor="#00CCFF" height="150%">
                            <div align="center">Folio</div>
                        </th>
                        <th scope="col" bgcolor="#00CCFF" height="150%">
                            <div align="center">Columna</div>
                        </th>
                        <th scope="col" bgcolor="#00CCFF" height="150%">
                            <div align="center">Línea comienzo</div>
                        </th>
                        <th scope="col" bgcolor="#00CCFF" height="150%">
                            <div align="center">Línea final</div>
                        </th>
                    </tr>

                    <tr>

                        <td>
                            <xsl:for-each
                                select="//tei:TEI//tei:phr[@function='adversative' and preceding-sibling::node()[1][self::tei:pc]]">
                                <div align="center">
                                    <xsl:value-of select="."/>
                                </div>
                                <hr/>
                            </xsl:for-each>
                        </td>
                        <td>
                            <xsl:for-each select="//tei:TEI//tei:phr[@function = 'adversative']">
                                <div align="center">
                                    <xsl:value-of select="ancestor::tei:div1/@n"/>
                                </div>
                                <hr/>
                            </xsl:for-each>
                        </td>
                        <td>
                            <xsl:for-each select="//tei:TEI//tei:phr[@function = 'adversative']">
                                <div align="center">
                                    <xsl:value-of select="ancestor::tei:div2/@n"/>
                                </div>
                                <hr/>
                            </xsl:for-each>
                        </td>
                        <td>
                            <xsl:for-each select="//tei:TEI//tei:phr[@function = 'adversative']">
                                <div align="center">
                                    <xsl:value-of select="preceding::tei:pb[@n][1]/@n"/>
                                </div>
                                <hr/>
                            </xsl:for-each>
                        </td>
                        <td>
                            <xsl:for-each select="//tei:TEI//tei:phr[@function = 'adversative']">
                                <div align="center">
                                    <xsl:value-of select="preceding::tei:cb[@n][1]/@n"/>
                                </div>
                                <hr/>
                            </xsl:for-each>
                        </td>
                        <td>
                            <xsl:for-each select="//tei:TEI//tei:phr[@function = 'adversative']">
                                <div align="center">
                                    <xsl:value-of select="preceding::tei:lb[@n][1]/@n"/>
                                </div>
                                <hr/>
                            </xsl:for-each>
                        </td>
                        <td>
                            <xsl:for-each select="//tei:TEI//tei:phr[@function = 'adversative']">
                                <div align="center">
                                    <xsl:value-of select="following::tei:lb[@n][1]/@n"/>
                                </div>
                                <hr/>
                            </xsl:for-each>
                        </td>
                    </tr>
                </table>
            </body>
        </html>

    </xsl:template>



</xsl:stylesheet>

对抗性协调
对抗性协调
利布罗
卡皮图罗
对开本
圆柱
莱尼亚·科米恩佐
利尼亚决赛







XML


标题
出版信息

关于来源的信息

德阿贝尔 这是一个很好的例子。 安达多斯特雷恩塔安诺斯;全多岛酒店 蒙多福克里亚多。 阿西·科莫·迪泽·马赫斯特·卢查斯·奥比斯波·德·苏伊;奥特罗斯·奎尔丹监狱 埃尔。亚当菲齐隆;尤拉·奥特罗·菲乔。∗这是一个很好的选择 亚伯。埃特阿贝尔 塞贡洛斯酒店 斯波尼米恩托斯是卡斯特拉诺的一个安静的图书馆。 塔托·科莫·洛罗·科萨 克诺内斯酒店 杜拉德拉。"创世格洛萨大教堂 sobre este logar。你知道吗。 这是我的最爱 baho se ua ayna&;东南方 埃斯帕泽·波尔埃尔·艾尔公司;非帕雷斯。 阿西·费莱西奥·艾娜·阿贝尔。 &;公共图书馆;不 帕雷西奥马斯。∗这是一个很好的例子。我的名字叫德尔博拉 这是我的秘密 我是赫尔马诺·阿贝尔。 公共交通 乌诺斯 uis公司poco como 埃尔。 他是我的朋友&;我是德尔博拉将军。 不需要特别注意 阿苏·赫尔马诺。你的生活是怎样的;安·邦达·阿曼多·迪奥斯。塔托公寓 乌伊斯科·阿尔坎索·阿苏·赫尔马诺·塞思。纳西奥·穆乔斯·安诺斯(que nasçio muchos annos)对德尔博拉(que delbora)进行了掠夺&;卡索·康奈尔。 这是我的最爱。
而不是

tei:phr[@function='adversative' and preceding-sibling::node()[1][self::tei:pc]]
试一试

这将提供以下输出

Non por que de muerte ella siguiesse assu hermano . mas por quel siguio en iusticia & en bondat amando a dios

下面的链接对前面的同级轴提供了很好的解释。

当前表达式不工作的原因是因为在
pc
节点和
phr
节点之间有一个空白节点,这就是表达式所拾取的内容

解决这个问题的一种方法是告诉XSLT忽略所有元素下的空白节点,方法是使用
xsl:strip space

<xsl:strip-space elements="*" />

或者,将表达式更改为仅检查元素,而不是节点

<xsl:for-each 
     select="//tei:TEI//tei:phr[@function='adversative' and preceding-sibling::*[1][self::tei:pc]]">

<xsl:strip-space elements="*" />
<xsl:for-each 
     select="//tei:TEI//tei:phr[@function='adversative' and preceding-sibling::*[1][self::tei:pc]]">