我正在尝试按照XSD架构安排xml节点顺序序列,但是它没有按预期工作。 在这里,尝试按照xsd模式将标记放入xml中。 这是标记之一。如果xml以任何顺序作为输入出现,则需要放置该标记,需要按照架构顺序按照预期的输出进行重新排列 请帮我解决。
如果我想更改架构以允许元素,以便如何更改xsd架构中“序列”中的元素。
输入XML
<Location>
<identifier>
<value value="Ide123" />
</identifier>
<managingOrganization>
<reference value="Test/vaaa" />
</managingOrganization>
<name value="Test name" />
</Location>
预期的输出XML:
<Location>
<identifier>
<value value="Ide123" />
</identifier>
<name value="Test name" />
<managingOrganization>
<reference value="Test/vaaa" />
</managingOrganization>
</Location>
输入XSD架构
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://hl7.org/fhir" xmlns:xhtml="http://www.w3.org/1999/xhtml" elementFormDefault="qualified" version="1.0">
<xs:include schemaLocation="fhir-base.xsd"/>
<xs:element name="Location" type="Location">
<xs:annotation>
<xs:documentation xml:lang="en">Details and position information for a physical place where services are provided and resources and participants may be stored, found, contained or accommodated.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:complexType name="Location">
<xs:annotation>
<xs:documentation xml:lang="en">Details and position information for a physical place where services are provided and resources and participants may be stored, found, contained or accommodated.</xs:documentation>
<xs:documentation xml:lang="en">If the element is present, it must have either a @value, an @id, or extensions</xs:documentation>
</xs:annotation>
<xs:complexContent>
<xs:extension base="DomainResource">
<xs:sequence>
<xs:element name="identifier" minOccurs="0" maxOccurs="unbounded" type="Identifier">
<xs:annotation>
<xs:documentation xml:lang="en">Unique code or number identifying the location to its users.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="status" minOccurs="0" maxOccurs="1" type="LocationStatus">
<xs:annotation>
<xs:documentation xml:lang="en">The status property covers the general availability of the resource, not the current value which may be covered by the operationStatus, or by a schedule/slots if they are configured for the location.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="operationalStatus" minOccurs="0" maxOccurs="1" type="Coding">
<xs:annotation>
<xs:documentation xml:lang="en">The Operational status covers operation values most relevant to beds (but can also apply to rooms/units/chair/etc such as an isolation unit/dialisys chair). This typically covers concepts such as contamination, housekeeping and other activities like maintenance.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="name" minOccurs="0" maxOccurs="1" type="string">
<xs:annotation>
<xs:documentation xml:lang="en">Name of the location as used by humans. Does not need to be unique.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="alias" minOccurs="0" maxOccurs="unbounded" type="string">
<xs:annotation>
<xs:documentation xml:lang="en">A list of alternate names that the location is known as, or was known as in the past.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="description" minOccurs="0" maxOccurs="1" type="string">
<xs:annotation>
<xs:documentation xml:lang="en">Description of the Location, which helps in finding or referencing the place.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="mode" minOccurs="0" maxOccurs="1" type="LocationMode">
<xs:annotation>
<xs:documentation xml:lang="en">Indicates whether a resource instance represents a specific location or a class of locations.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="type" minOccurs="0" maxOccurs="1" type="CodeableConcept">
<xs:annotation>
<xs:documentation xml:lang="en">Indicates the type of function performed at the location.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="telecom" minOccurs="0" maxOccurs="unbounded" type="ContactPoint">
<xs:annotation>
<xs:documentation xml:lang="en">The contact details of communication devices available at the location. This can include phone numbers, fax numbers, mobile numbers, email addresses and web sites.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="address" minOccurs="0" maxOccurs="1" type="Address">
<xs:annotation>
<xs:documentation xml:lang="en">Physical location.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="physicalType" minOccurs="0" maxOccurs="1" type="CodeableConcept">
<xs:annotation>
<xs:documentation xml:lang="en">Physical form of the location, e.g. building, room, vehicle, road.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="position" type="Location.Position" minOccurs="0" maxOccurs="1">
<xs:annotation>
<xs:documentation xml:lang="en">The absolute geographic location of the Location, expressed using the WGS84 datum (This is the same co-ordinate system used in KML).</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="managingOrganization" minOccurs="0" maxOccurs="1" type="Reference">
<xs:annotation>
<xs:documentation xml:lang="en">The organization responsible for the provisioning and upkeep of the location.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="partOf" minOccurs="0" maxOccurs="1" type="Reference">
<xs:annotation>
<xs:documentation xml:lang="en">Another Location which this Location is physically part of.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="endpoint" minOccurs="0" maxOccurs="unbounded" type="Reference">
<xs:annotation>
<xs:documentation xml:lang="en">Technical endpoints providing access to services operated for the location.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="Location.Position">
<xs:annotation>
<xs:documentation xml:lang="en">Details and position information for a physical place where services are provided and resources and participants may be stored, found, contained or accommodated.</xs:documentation>
</xs:annotation>
<xs:complexContent>
<xs:extension base="BackboneElement">
<xs:sequence>
<xs:element name="longitude" minOccurs="1" maxOccurs="1" type="decimal">
<xs:annotation>
<xs:documentation xml:lang="en">Longitude. The value domain and the interpretation are the same as for the text of the longitude element in KML (see notes below).</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="latitude" minOccurs="1" maxOccurs="1" type="decimal">
<xs:annotation>
<xs:documentation xml:lang="en">Latitude. The value domain and the interpretation are the same as for the text of the latitude element in KML (see notes below).</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="altitude" minOccurs="0" maxOccurs="1" type="decimal">
<xs:annotation>
<xs:documentation xml:lang="en">Altitude. The value domain and the interpretation are the same as for the text of the altitude element in KML (see notes below).</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:simpleType name="LocationMode-list">
<xs:restriction base="code-primitive">
<xs:enumeration value="instance">
<xs:annotation>
<xs:documentation xml:lang="en">Instance</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="kind">
<xs:annotation>
<xs:documentation xml:lang="en">Kind</xs:documentation>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="LocationMode">
<xs:annotation>
<xs:documentation xml:lang="en">Indicates whether a resource instance represents a specific location or a class of locations.</xs:documentation>
<xs:documentation xml:lang="en">If the element is present, it must have either a @value, an @id, or extensions</xs:documentation>
</xs:annotation>
<xs:complexContent>
<xs:extension base="Element">
<xs:attribute name="value" type="LocationMode-list" use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:simpleType name="LocationStatus-list">
<xs:restriction base="code-primitive">
<xs:enumeration value="active">
<xs:annotation>
<xs:documentation xml:lang="en">Active</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="suspended">
<xs:annotation>
<xs:documentation xml:lang="en">Suspended</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="inactive">
<xs:annotation>
<xs:documentation xml:lang="en">Inactive</xs:documentation>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="LocationStatus">
<xs:annotation>
<xs:documentation xml:lang="en">Indicates whether the location is still in use.</xs:documentation>
<xs:documentation xml:lang="en">If the element is present, it must have either a @value, an @id, or extensions</xs:documentation>
</xs:annotation>
<xs:complexContent>
<xs:extension base="Element">
<xs:attribute name="value" type="LocationStatus-list" use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
XSLT代码
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="xml" indent="yes" />
<xsl:key name="kxsElemByName" match="xs:element" use="@name"/>
<xsl:key name="kxsTypeByName" match="xs:complexType" use="@name"/>
<xsl:variable name="vSchema" select="document('file:///C:/Users/310271854/Amina/location.xsd')"/>
<xsl:template match="*[descendant::text() or descendant-or-self::*/@*[string()]]">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="node()|@*">
<xsl:variable name="current" select="." />
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<xsl:for-each select="$vSchema">
<xsl:variable name="element" select="key('kxsElemByName', name($current))" />
<xsl:variable name="complexContent" select="key('kxsTypeByName', $element/@name)" />
<xsl:choose>
<xsl:when test="$complexContent">
<xsl:for-each select="$complexContent/xs:extension/xs:sequence/xs:element">
<xsl:apply-templates select="$current/*[name() = current()/@name]" />
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="$current/node()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>