重命名文檔中某些元素的最簡單方法是使用標識轉換,然後爲要更改的元素添加一些模板。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- modify just the row_item with the specified attribute value -->
<xsl:template match="row_item[@column='Hostname']">
<hostname>
<xsl:apply-templates />
</hostname>
</xsl:template>
<!-- the identity template -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
隨着
<rows>
<row_item column="Hostname">HOST-A</row_item>
<row_item column="IP Address">10.10.10.10</row_item>
</rows>
一個示例XML這種轉變爲
<rows>
<hostname>HOST-A</hostname>
<row_item column="IP Address">10.10.10.10</row_item>
</rows>
你能解釋清楚一點嗎?輸出XML中的元素名稱是否爲動態?如果是這樣,它是基於'column'屬性值嗎?第二個'row_item'呢? – 2012-02-03 13:58:39