[英]Transform XML from old schema to new schema?
我需要將不使用任何模式的XML文檔轉換為使用定義良好的模式的另一種格式。
因此,基本上我必須對此進行轉換:
<healthCareFacilityTypeCode
displayName="Home"
codingScheme="Connect-a-thon healthcareFacilityTypeCodes"
>Home</healthCareFacilityTypeCode>
變成這個:
<healthCareFacilityTypeCode>
<code>Home</code>
<displayName>
<LocalizedString value="Home" />
</displayName>
<schemeName>Connect-a-thon healthcareFacilityTypeCodes</schemeName>
</healthCareFacilityTypeCode>
我知道如何通過查看架構來手動轉換它。 這是XSD的片段:
<xsd:complexType name="DocumentEntryType">
<xsd:sequence>
<xsd:element minOccurs="0"
name="healthCareFacilityTypeCode"
type="tns:CodedMetadataType"/>
</xsd:sequence>
<xsd:attribute default="false"
name="existing"
type="xsd:boolean"
use="optional"/>
</xsd:complexType>
<xsd:element name="DocumentEntry" type="tns:DocumentEntryType"/>
我不知道如何解決:如何利用目標XSD將節點從源XML轉換為目標XML文檔。 我覺得執行轉換的所有信息都位於XSD中,但是我可以使用它嗎? 怎么樣?
任何幫助將不勝感激!
遵循建議,這就是我的想法。 雖然不完美,但足以滿足我的目的。
<xsl:template match="XDSDocumentEntry">
<DocumentEntryType>
<xsl:call-template name="namespaceChange"/>
<xsl:apply-templates/>
</DocumentEntryType>
</xsl:template>
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//*[matches(name(), 'Code')]">
<xsl:copy>
<code>
<xsl:value-of select="."/>
</code>
<schemeName>
<xsl:value-of select="@codingScheme"/>
</schemeName>
<displayName>
<LocalizedString>
<xsl:attribute name="value">
<xsl:value-of select="@displayName"/>
</xsl:attribute>
</LocalizedString>
</displayName>
</xsl:copy>
</xsl:template>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.