簡體   English   中英

如何使用xslt部分轉換xml?

[英]How to partially transform xml using xslt?

我正在嘗試進行一些XML數據遷移,將xml文檔從一種模式遷移到另一種更新版本。 更改不會很大,所以我想知道xslt是否有一種簡單的方法來僅部分轉換xml。 例如,僅重命名元素名稱,等等。

XSLT接受輸入文檔並創建一個新的輸出文檔。 對於進行小的更改,是的,使用身份轉換模板開始樣式表,並為更改添加更多特定的模板,例如

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

<!-- identity transformation template -->
<xsl:template match="@* | node()">
  <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
  </xsl:copy>
</xsl:template>

<!-- rename foo to bar elements -->
<xsl:template match="foo">
  <bar>
    <xsl:apply-templates select="@* | node()"/>
  </bar>
</xsl:template>

</xsl:stylesheet>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM