W3C home > Mailing lists > Public > xmlschema-dev@w3.org > April 2009

RE: Conditional Levels of a Schema

From: Michael Kay <mike@saxonica.com>
Date: Tue, 7 Apr 2009 15:21:19 +0100
To: "'Dieter Menne'" <dieter.menne@menne-biomed.de>, <xmlschema-dev@w3.org>
Message-ID: <A588DDAB9F3D436BA2C5F5D0C9EC8C46@Sealion>
This transformation isn't reliable.

You're using <xsl:apply-templates select="@*"/> to process all the
attributes, and the result will depend on the order in which they are
processed, which isn't predictable. A safer approach would be

<xsl:copy-of select="@*"/>
<xsl:apply-templates select="@hrm:*"/>

(if you create two attributes with the same name in XSLT, the last one
wins.)

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: xmlschema-dev-request@w3.org 
> [mailto:xmlschema-dev-request@w3.org] On Behalf Of Dieter Menne
> Sent: 07 April 2009 14:41
> To: xmlschema-dev@w3.org
> Subject: RE: Conditional Levels of a Schema
> 
> 
> In case someone is going to need it, here is Pete's suggestion:
> 
> The Master Schema
> 
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="0.3"
>    xmlns:hrm="http://www.hrmconsensus.org/layers">
> 	<xs:element name="xhrm">
> 		<xs:complexType>
> 			<xs:sequence>
> 				<xs:element name="device" 
> type="xs:string"/>
> 				<xs:element minOccurs="0" 
> maxOccurs="1" name="patient" 
> 				   type="xs:string" 
> hrm:patientInfo="1"/>
> 			</xs:sequence>
> 		</xs:complexType>
> 	</xs:element>
> </xs:schema>
> 
> 
> Use xsl to convert it to a another xsd where patient info is 
> required. I tried to use result-document with it, but could 
> not get the syntax correct. 
> 
> <?xml version="1.0"?>
> <xsl:stylesheet version="2.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:hrm="http://www.hrmconsensus.org/layers">
>   <xsl:output method="xml" indent="no"/>
>   <xsl:template match="node()|@*">
>     <xsl:copy>
>       <xsl:apply-templates select="@*"/>
>       <xsl:apply-templates/>
>     </xsl:copy>
>   </xsl:template>
> 
>   <xsl:template match="@hrm:patientInfo">
>     <xsl:attribute name="minOccurs">
>       <xsl:value-of select="1"/>
>     </xsl:attribute>
>   </xsl:template>
> </xsl:stylesheet>
> 
> 
> --
> View this message in context: 
> http://www.nabble.com/Conditional-Levels-of-a-Schema-tp2290517
> 9p22929208.html
> Sent from the w3.org - xmlschema-dev mailing list archive at 
> Nabble.com.
> 
> 
Received on Tuesday, 7 April 2009 14:21:59 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:15:11 GMT