簡體   English   中英

如何使用 XSLT1.0 從 XML 中刪除類型屬性

[英]How to remove type attribute from XML using XSLT1.0

假設我有一個如下所示的 XML。

<CustomerOrder>
   <CustomerId type="string">1000</CustomerId>
   <CustomerName type="string">Johnny</CustomerName>
   <Age type="Number">20</Age>
</CustomerOrder>

我需要編寫 XSL 轉換器,以便我可以刪除類型屬性,最終的 output 應該如下所示。

<CustomerOrder>
   <CustomerId>1000</CustomerId>
   <CustomerName>Johnny</CustomerName>
   <Age>20</Age>
</CustomerOrder>

有任何想法嗎??

只需使用此樣式表即可實現第一條評論中的建議:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>

  <!-- identity template - copies everything as it is except for other rules matching -->
  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*" />
    </xsl:copy>
  </xsl:template>  
  
  <!-- Match all type attributes and ignore them -->
  <xsl:template match="@type" />

</xsl:stylesheet>

暫無
暫無

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

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