Xslt XSL:使用XSL将xml转换为输出

Xslt XSL:使用XSL将xml转换为输出,xslt,xslt-2.0,Xslt,Xslt 2.0,请帮助编写xsl: 我得到了这个xml: <?xml version="1.0" encoding="utf-8"?> <root> <Table name = "My table1"> <Row isHeader="True"> <Cell val ="Header1"> </Cell> <Cell val ="Header2"> </Cell> <Cell val ="Header3">

请帮助编写xsl:

我得到了这个xml:

<?xml version="1.0" encoding="utf-8"?>
<root>
<Table name = "My table1">
<Row isHeader="True">
<Cell val ="Header1"> </Cell>
<Cell val ="Header2"> </Cell>
<Cell val ="Header3"> </Cell>
</Row>
<Row isHeader="False">
<Cell val ="Data2.1"> </Cell>
<Cell val ="Data2.2"> </Cell>
<Cell val ="Data2.3"> </Cell>
</Row>
<Row>
<Cell val ="Data3.1"> </Cell>
<Cell val ="Data3.2"> </Cell>
<Cell val ="Data3.3"> </Cell>
</Row>
</Table>
</root>

到此输出:第一行包含标题

<?xml version="1.0" encoding="utf-8"?>
<items>
<item>Header1=Data2.1 Header2=Data2.2 Header3=Data2.3 </item>
<item>Header1=Data3.1 Header2=Data3.2 Header3=Data3.3 </item>
</items>

Header1=Data2.1 Header2=Data2.2 Header3=Data2.3
Header1=Data3.1 Header2=Data3.2 Header3=Data3.3
非常感谢你的帮助


<xsl:template match="Table">
 <xsl:variable name='headers' select="Row[1]"/>
 <xsl:for-each select="remove(Row, 1)">
   <item><xsl:value-of 
            select="for $i in 1 to count($headers/Cell) 
                    return concat($headers/Cell[$i], '=', Cell[$i])"/>
   </item>
 </xsl:for-each>
</xsl:template>
未测试。

以下是我的建议:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output indent="yes"/>

<xsl:template match="Table">
  <items>
    <xsl:variable name="headers" select="Row[1]/Cell/@val"/>
    <xsl:for-each select="Row[position() gt 1]">
      <item>
        <xsl:for-each select="Cell">
          <xsl:if test="position() gt 1"><xsl:text> </xsl:text></xsl:if>
          <xsl:variable name="pos" select="position()"/>
          <xsl:value-of select="concat($headers[$pos], '=', @val)"/>
        </xsl:for-each>
      </item>
    </xsl:for-each>
  </items>
</xsl:template>

</xsl:stylesheet>


假设输出XML是下面“to output:”框中的代码,则此问题中似乎没有写入输入XML!这里是源xml!我相信您需要一个
元素。