我有一個XML文檔,其中有不同級別的附加節點,我想通過XSLT刪除它。我的直覺是生成一個XSD(使用Altova之類),刪除我不想出現在我的輸出中的元素,然後讓編輯器(Altova等)自動生成一個XSLT來轉換將舊的XSD添加到新的XSD中。從XML中刪除值的最簡單方法是什麼
回到當天,我過去一直用手寫XSL ......但所有這些很酷的工具,真的有理由或有人可以提出另一種方法嗎?我沒有做過這個東西,在幾年,所以我想我會問...
最後我想出這一點,這是非常簡單的,所以感謝您的建議:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" >
<xsl:output method="xml" indent="yes"/>
<xsl:template xpath-default-namespace="http://www.tempuri.org" match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template xpath-default-namespace="http://www.tempuri.org" match="SomeNode">
</xsl:template>
<xsl:template xpath-default-namespace="http://www.tempuri.org" match="TheNode[@type!='SomeType' and @type!='OtherType']">
</xsl:template>
</xsl:stylesheet>
我需要做的一件事是檢查「TheNode」中缺少的元素「SomeSubElement」,如果缺少它,則插入一個空元素。
有關如何做到這一點的任何建議?謝謝。
至於原因去,它可能更快地編寫XSLT比XSD ... – annakata 2010-11-02 14:59:21
首先,這是另一個問題。你應該再問一次。其次,這不是處理QNames的方法:在'stylesheet'根元素中只放入一個'xpath-default-namespace =「http://www.tempuri.org」,或者放入一個命名空間聲明'xmlns :temp =「http://www.tempuri.org」在'stylesheet'根元素中,並使用模式中的完整QName,如'temp:SomeNode' – 2010-11-02 21:32:08