XSLT使用XSD属性修改XML

时间:2015-06-18 04:46:57

标签: xml xslt xsd

我想使用XSD的属性修改我的XML代码。

XSD:

<xsd:schema xmlns:xsd="uri" xmlns:vc="uri_1" xmlns="uri_2" targetNamespace="uri_3" elementFormDefault="qualified" attributeFormDefault="unqualified" vc:minVersion="1.1">
<xsd:include schemaLocation="PolicyAdminGroupBenefits.xsd" /> 

<xsd:element name="FrequencyCode" type="xsd:string" /> 
<xsd:element name="BankAccountNumber" type="xsd:string" /> 
<xsd:element name="AmericanBankersAssociationRoutingNumber" type="xsd:string" /> 
<xsd:element name="BankAccount" type="BankAccount_Type" /> 
<xsd:element name="ElectronicFundsTransferPaymentTransaction" type="ElectronicFundsTransferPaymentTransaction_Type" />

<xsd:complexType name="ElectronicFundsTransferPaymentTransaction_Type">
<xsd:sequence>
<xsd:element ref="FrequencyCode" minOccurs="0" /> 
<xsd:element ref="BankAccount" minOccurs="0" maxOccurs="1" /> 
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="BankAccount_Type">
<xsd:sequence>
<xsd:element ref="AmericanBankersAssociationRoutingNumber" minOccurs="0" /> 
<xsd:element ref="BankAccountNumber" minOccurs="0" />  
</xsd:sequence>
</xsd:complexType>

XML代码:

   <EmployerViewRootElement xmlns="uri_2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="uri_2 EmployerView.xsd">
   <ElectronicFundsTransferPaymentTransaction>
   <FrequencyCode>String</FrequencyCode> 
   <BankAccount>
   <AmericanBankersAssociationRoutingNumber>String</AmericanBankersAssociationRoutingNumber> 
   <BankAccountNumber>String</BankAccountNumber>  
   </BankAccount>
   </ElectronicFundsTransferPaymentTransaction>
   </EmployerViewRootElement>

我想编写XSLT代码,该代码将使用来自XSD的maxOccurs属性来检查强制节点(即,如果maxOccurs="1"那么元素是必需的)&amp;如果源xml中没有这些元素,则抛出错误。是否可以编写这样的代码? 非常感谢任何帮助!

0 个答案:

没有答案