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 若变量包含一个集合,那个么我如何到达第二项_Xml_Xslt - Fatal编程技术网

Xml 若变量包含一个集合,那个么我如何到达第二项

Xml 若变量包含一个集合,那个么我如何到达第二项,xml,xslt,Xml,Xslt,如何在下面的示例中显示Hola?现在,它正在回复你好 xml xsl 可以通过将testVar声明移动到模板中并相对于当前位置使用它来实现这一点 正如您所看到的,testVar只计算具有该路径的所有节点,其中有两个节点 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html"/> <xsl:templat

如何在下面的示例中显示Hola?现在,它正在回复你好

xml

xsl


可以通过将testVar声明移动到模板中并相对于当前位置使用它来实现这一点

正如您所看到的,testVar只计算具有该路径的所有节点,其中有两个节点

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="html"/>

  <xsl:template match="greetings">
    <xsl:apply-templates select="greeting[@id &gt; 1]"/>
  </xsl:template>

  <xsl:template match="greeting">
    <xsl:variable name="testVar" select="can/be/a/long[@itemNo=1]" />
    <html>
      <body>
        <h1>
          <xsl:value-of select="$testVar/path"/>
        </h1>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>
仅供参考,如果您想访问节点集中的第二项,可以使用[2]来访问:$testVar[2]/path,但是在您的示例中这样做会破坏使用模板的目的

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="html"/>

  <xsl:template match="greetings">
    <xsl:apply-templates select="greeting[@id &gt; 1]"/>
  </xsl:template>

  <xsl:variable name="testVar" select="/greetings/greeting/can/be/a/long[@itemNo=1]" />

  <xsl:template match="greeting">
    <html>
      <body>
        <h1>
          <xsl:value-of select="$testVar/path"/>
        </h1>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="html"/>

  <xsl:template match="greetings">
    <xsl:apply-templates select="greeting[@id &gt; 1]"/>
  </xsl:template>

  <xsl:template match="greeting">
    <xsl:variable name="testVar" select="can/be/a/long[@itemNo=1]" />
    <html>
      <body>
        <h1>
          <xsl:value-of select="$testVar/path"/>
        </h1>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>