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 xsl:number-only具有特定值的元素_Xml_Xslt - Fatal编程技术网

Xml xsl:number-only具有特定值的元素

Xml xsl:number-only具有特定值的元素,xml,xslt,Xml,Xslt,我有以下结构 <item name="key_1">D</item> <item name="content_1">Ringo</item> <item name="key_2">G</item> <item name="content_2">John</item> <item name="key_3&qu

我有以下结构

<item name="key_1">D</item>
<item name="content_1">Ringo</item>
<item name="key_2">G</item>
<item name="content_2">John</item>
<item name="key_3">G</item>
<item name="content_3">George</item>
<item name="key_4">B</item>
<item name="content_4">Paul</item>
D
林戈
G
约翰
G
乔治
B
保罗
我想把它转换成这样:

<table>
    <tr>
        <td>No.</td>
        <td>Name</td>
    </tr>
    <tr>
        <td>1</td>
        <td>John</td>
    </tr>
    <tr>
        <td>2</td>
        <td>George</td>
    </tr>
</table>

不
名称
1.
约翰
2.
乔治
我只想接管content类型的元素,谁的关键是“G”。我不知道我有多少个“G”,也不知道它们在列表中的什么位置。

我的问题是结果表行的编号。数字必须是从1到“G”元素数的普通数字。但是
将导致我的示例的所有关键元素计算在行号“2”和“3”中。此处不允许进行比较。

您只需根据条件选择项目,并使用
position()
作为编号:

  <xsl:template match="items">
      <table>
          <thead>
              <tr>
                  <th>No.</th>
                  <th>Name</th>
              </tr>
          </thead>
          <tbody>
              <xsl:apply-templates select="item[@name[starts-with(., 'key_')] and . = 'G']"/>
          </tbody>
      </table>
  </xsl:template>
  
  <xsl:template match="item">
      <tr>
          <td>
              <xsl:value-of select="position()"/>
          </td>
          <td>
              <xsl:value-of select="following-sibling::item[1]"/>
          </td>
      </tr>
  </xsl:template>

不
名称

如果要使用xsl:number,请将count属性与正确的谓词一起使用:

对不起,我的错。。。。我的意思是
xsl:number count=
,而不是
xsl:number select=
,这就是我的问题。。。正确的谓词。因为这里不允许进行比较。
在这个select表达式中不全是lowed。我不明白为什么它不起作用,这是使用position()和xsl:number的方法。您使用哪个XSLT处理器,您能给出准确的错误消息和准确的代码示例吗
xsl:number count=“/item/@[以(name,'key')]='G'/>
在XPath级别上显然是语法错误的。没有正确读取计数谓词。将所有条件放入谓词中解决了它。非常感谢。