[英]Rename tag in XML using XSLT
我有一個像下面的XML:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<properties>
<entry key="user">1234</entry>
<entry key="name">sam</entry>
</properties>
我想使用xslt修改鍵值(key =“ user”到key =“ id”),輸出xml應該像這樣
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<properties>
<entry key="id">1234</entry>
<entry key="call">sam</entry>
</properties>
有人可以幫我嗎? 因為我對XSLT領域非常陌生。
為此,您必須首先使用標識轉換而不是處理鍵來轉換它:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"></xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="@key[. = 'user']">
<xsl:attribute name="key">id</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.