有没有办法根据属性输出值?
我对 XSLT 很陌生,所以如果很明显,请多多包涵:)
我有一个如下所示的 XML:
<Columns>
<Column DataType="String">Id</Column>
<Column DataType="String">FirstName</Column>
<Column DataType="String">LastName</Column>
<Column DataType="String">TheDescription</Column>
</Columns>
<Rows>
<Row>
<Value Column="Id">1</Value>
<Value Column="FirstName">John</Value>
<Value Column="LastName">Doe</Value>
<Value Column="TheDescription">Some description about John Doe</Value>
</Row>
<Row>
<Value Column="Id">2</Value>
<Value Column="FirstName">Jane</Value>
<Value Column="LastName">Doe</Value>
<Value Column="TheDescription">Some description about Jane Doe</Value>
</Row>
</Rows>
我尝试执行以下操作:
<xsl:template match="Template">
<xsl:apply-templates select="loop[@name='Rows']" />
</xsl:template>
<xsl:template match="loop[@name='Rows']">
<table border="1" cellpadding="2" cellspacing="2">
<tr>
<xsl:apply-templates select="../loop[@name='Columns']/item" mode="header" />
</tr>
<xsl:apply-templates select="item" mode="row" />
</table>
</xsl:template>
<xsl:template match="item" mode="row">
<tr>
<xsl:apply-templates select="loop[@name='Row']" />
</tr>
</xsl:template>
<xsl:template match="loop[@name='Row']">
<xsl:param name="Column" />
<xsl:if test="$Column = FirstName">
<td>Output the value of FirstName here!</td>
</xsl:if>
</xsl:template>
最后 6 行应输出 FirstName。怎么可能呢?