誰能給我轉換XML架構模板等等的範例......到其他XML模式模板?
XML Schema只是一個聲明名稱空間爲uri http://www.w3.org/2001/XMLSchema
的XML文檔。因此,您可以照常應用XSLT。
例如,你有一個源架構是這樣的:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="carareWrap">
<xs:annotation>
<xs:documentation xml:lang="en">The CARARE wrapper element. It wraps CARARE elements.</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="unbounded" ref="carare"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
和(例如)要刪除僅供參考元素的屬性。您可以採用以下變換:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="xs:element[@ref]">
<xsl:copy>
<xsl:copy-of select="@ref"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
結果將是:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="carareWrap">
<xs:annotation>
<xs:documentation xml:lang="en">The CARARE wrapper element. It wraps CARARE elements.</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref="carare" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
注意
- 將需要輸入文檔的命名空間的聲明在XSLT中
- 使用身份轉換按原樣複製輸入文檔並按要求覆蓋元素。
+1我想我可以去,現在刪除我的答案。 ;) – Tomalak 2011-06-14 11:26:11