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中获取表列标题?_Xml_Xslt_Xmltable - Fatal编程技术网

Xml 如何";“展望未来”;在XSL中获取表列标题?

Xml 如何";“展望未来”;在XSL中获取表列标题?,xml,xslt,xmltable,Xml,Xslt,Xmltable,我的XML结构如下所示: <Root> <Node Name="File System"> <Node Name="C:\Windows\System32\drivers\etc\hosts"> <Table> <Row> <Column Name="Name" Value="localhost" /> <Column Name="IP"

我的XML结构如下所示:

<Root>
  <Node Name="File System">
    <Node Name="C:\Windows\System32\drivers\etc\hosts">
      <Table>
        <Row>
          <Column Name="Name" Value="localhost" />
          <Column Name="IP" Value="127.0.0.1" />
        </Row>
        <Row>
        .....
    </Node>
  </Node>
</Root>

.....
我有xslt代码来遍历节点和表,但当我想以某种方式获取列名作为标题时,我就被卡住了

以下是工作代码(除抓取列标题外):

<xsl:template match="Root">
  <ul>
    <xsl:apply-templates select="Node" />
  </ul>
 </xsl:template>

<xsl:template match="Node">
  <li>
    <xsl:value-of select="@Name" />
    <xsl:if test="Node">
      <ul>
        <xsl:apply-templates select="Node" />
      </ul>
    </xsl:if>
    <xsl:if test="Attributes">
      <xsl:apply-templates select="Attributes" />
    </xsl:if>
    <xsl:if test="Table">
      <xsl:apply-templates select="Table" />
    </xsl:if>
  </li>
</xsl:template>

<xsl:template match="Attributes">
  <ul>
    <xsl:apply-templates select="Attribute" />
  </ul>
</xsl:template>

<xsl:template match="Attribute">
  <li>
    <b><xsl:value-of select="@Name" />:</b> <xsl:value-of select="@Value" />
  </li>
</xsl:template>

<xsl:template match="Table">
  <table border="1">
    <tbody>
      <xsl:apply-templates select="Row" />
    </tbody>
  </table>
</xsl:template>

<xsl:template match="Row">
  <tr>
    <xsl:apply-templates select="Column" />
  </tr>
</xsl:template>

<xsl:template match="Column">
  <td>
    <xsl:value-of select="@Value" />
  </td>
</xsl:template>

  • :
  • 那么:

    <xsl:template match="Row" mode="thead">
      <th>
        <xsl:apply-templates select="Column" mode="thead"/>
      </th>
    </xsl:template>
    
    <xsl:template match="Column" mode="thead">
      <td>
        <xsl:value-of select="@Name" />
      </td>
    </xsl:template>
    

    非常感谢!我刚刚将“th”标记改为“tr”,效果非常好。我假设一旦应用了第一行,我就不能再使用它了,但这只是我误解了模板的工作原理。再次感谢!
    <xsl:template match="Table">
      <table border="1">
        <thead>
          <xsl:apply-templates select="Row[1]" mode="thead"/>
        </thead>
        <tbody>
          <xsl:apply-templates select="Row" />
        </tbody>
      </table>
    </xsl:template>