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 基于条件值显示的XPATH ********************* . . *******************_Xslt_Xpath - Fatal编程技术网

Xslt 基于条件值显示的XPATH ********************* . . *******************

Xslt 基于条件值显示的XPATH ********************* . . *******************,xslt,xpath,Xslt,Xpath,在上面的结构中,我想从或检索文本。i、 e.使用一个xpath条件,我需要具有以下条件的值 1) 如果未出现,则。副弗索也 2)两个标题都是可用的,然后我想考虑NeXST节点值。i、 e.在上述结构中,“”是最新的节点。因此,换句话说,您只需要出现在章节下的最后一个概念/标题或章节/标题?这个XPath应该可以做到这一点(假设当前上下文是章节: <chapter> <concept> <title>******************

在上面的结构中,我想从
检索文本。i、 e.使用一个xpath条件,我需要具有以下条件的值

1) 如果未出现
,则
。副弗索也


2)两个标题都是可用的,然后我想考虑NeXST节点值。i、 e.在上述结构中,“

”是最新的节点。

因此,换句话说,您只需要出现在
章节下的最后一个
概念/标题
章节/标题
?这个XPath应该可以做到这一点(假设当前上下文是
章节

<chapter>
    <concept>
        <title>*********************</title>
    .
    .
    </concept>

    <sections>
       <title>*******************</title>

</chapter>

因此,换句话说,您只需要出现在
章节
下的最后一个
概念/标题
章节/标题
?这个XPath应该可以做到这一点(假设当前上下文是
章节

<chapter>
    <concept>
        <title>*********************</title>
    .
    .
    </concept>

    <sections>
       <title>*******************</title>

</chapter>
您想要两个中“最接近的”(第一个):

(concept/title | sections/title)[last()]
(/*/*[self::concept or self::sections]/title)[last()]
如果您想要最新的(最后一个),请使用:

(/*/*[self::concept or self::sections]/title)[1]
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="/">
  <xsl:copy-of select=
     "(/*/*[self::concept or self::sections]/title)[1]"/>
===============
  <xsl:copy-of select=
     "(/*/*[self::concept or self::sections]/title)[last()]"/>
 </xsl:template>
</xsl:stylesheet>
<chapter>
    <concept>
        <title>*********Title 1************</title>
    .
    .
    </concept>

    <sections>
       <title>**********Title 2*********</title>
    </sections>

</chapter>

基于XSLT的验证

(concept/title | sections/title)[last()]
(/*/*[self::concept or self::sections]/title)[last()]

===============
当此转换应用于以下XML文档时:

(/*/*[self::concept or self::sections]/title)[1]
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="/">
  <xsl:copy-of select=
     "(/*/*[self::concept or self::sections]/title)[1]"/>
===============
  <xsl:copy-of select=
     "(/*/*[self::concept or self::sections]/title)[last()]"/>
 </xsl:template>
</xsl:stylesheet>
<chapter>
    <concept>
        <title>*********Title 1************</title>
    .
    .
    </concept>

    <sections>
       <title>**********Title 2*********</title>
    </sections>

</chapter>

*********标题1************
.
.
**********标题2*********
计算两个XPath表达式并将其结果复制到输出:

(/*/*[self::concept or self::sections]/title)[1]
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="/">
  <xsl:copy-of select=
     "(/*/*[self::concept or self::sections]/title)[1]"/>
===============
  <xsl:copy-of select=
     "(/*/*[self::concept or self::sections]/title)[last()]"/>
 </xsl:template>
</xsl:stylesheet>
<chapter>
    <concept>
        <title>*********Title 1************</title>
    .
    .
    </concept>

    <sections>
       <title>**********Title 2*********</title>
    </sections>

</chapter>
**********标题1************
===============
**********标题2*********
您想要两个中“最近的”(第一个):

(concept/title | sections/title)[last()]
(/*/*[self::concept or self::sections]/title)[last()]
如果您想要最新的(最后一个),请使用:

(/*/*[self::concept or self::sections]/title)[1]
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="/">
  <xsl:copy-of select=
     "(/*/*[self::concept or self::sections]/title)[1]"/>
===============
  <xsl:copy-of select=
     "(/*/*[self::concept or self::sections]/title)[last()]"/>
 </xsl:template>
</xsl:stylesheet>
<chapter>
    <concept>
        <title>*********Title 1************</title>
    .
    .
    </concept>

    <sections>
       <title>**********Title 2*********</title>
    </sections>

</chapter>

基于XSLT的验证

(concept/title | sections/title)[last()]
(/*/*[self::concept or self::sections]/title)[last()]

===============
当此转换应用于以下XML文档时:

(/*/*[self::concept or self::sections]/title)[1]
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="/">
  <xsl:copy-of select=
     "(/*/*[self::concept or self::sections]/title)[1]"/>
===============
  <xsl:copy-of select=
     "(/*/*[self::concept or self::sections]/title)[last()]"/>
 </xsl:template>
</xsl:stylesheet>
<chapter>
    <concept>
        <title>*********Title 1************</title>
    .
    .
    </concept>

    <sections>
       <title>**********Title 2*********</title>
    </sections>

</chapter>

*********标题1************
.
.
**********标题2*********
计算两个XPath表达式并将其结果复制到输出:

(/*/*[self::concept or self::sections]/title)[1]
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="/">
  <xsl:copy-of select=
     "(/*/*[self::concept or self::sections]/title)[1]"/>
===============
  <xsl:copy-of select=
     "(/*/*[self::concept or self::sections]/title)[last()]"/>
 </xsl:template>
</xsl:stylesheet>
<chapter>
    <concept>
        <title>*********Title 1************</title>
    .
    .
    </concept>

    <sections>
       <title>**********Title 2*********</title>
    </sections>

</chapter>
**********标题1************
===============
**********标题2*********

@hr_117,不客气。是的,这比从联合中指定第一个节点更有效,除非已知使用的XPath处理器正在优化此类表达式。@hr_117,不客气。是的,这比从联合中指定第一个节点更有效,除非已知使用的XPath处理器是optimizi我不喜欢这样的表达。