RE: [xsl] re-ordering an instance to match a schema

Subject: RE: [xsl] re-ordering an instance to match a schema
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sun, 15 Apr 2007 11:21:49 +0100
It's a two-part problem: first you have to find some way of reading the
content model from the schema, then you have to do the sort.

If the content model is something like (a* | b*a* | (cba)*) then I think
it's a pretty tough problem, and you'll have to search the computer science
literature to see if any algorithms exist. 

If it's a more constrained content model, for example if it's a sequence of
elements each of which can only occur zero-or-one times, then it becomes
more tractable. For example, once you've worked out how to read the content
model, you can build a structure that maps the element names to positions
like this:

<contentModel>
  <element name="p" position="1"/>
  <element name="q" position="2"/>
  ...
</contentModel>

and then do

  <xsl:sort
select="$contentModel/element[@name=local-name(current())]/number(@position)
"/>

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

> -----Original Message-----
> From: Joe McDuffey [mailto:jdmcduf@xxxxxxxxx] 
> Sent: 15 April 2007 08:59
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] re-ordering an instance to match a schema 
> 
> There was a thread back in 2003 concerning
> 
>    Subject: Re: [xsl] re-ordering an instance to match a schema
>    From: S Woodside <sbwoodside@xxxxxxxxx
>    <mailto:sbwoodside@xxxxxxxxxxxxx>>
>    Date: Wed, 14 May 2003 19:35:25 -0400
> 
> I don't know if this was ever resolved, but I would like to 
> know if there exists a stylesheet to reorder an instance that 
> would be in the sequential order of a Schema e.g. relanNG or 
> W3C. I need this as a  step prior to validation.. Can anyone 
> help. Thanks.
> 
> --
> Joe McDuffey
> JONY Software Solutions
> "An ISO 9001:2000 Certified Company"
> jdmcduf@xxxxxxxxxxxxxxxxx
> 410.884.5355 (Office)
> 443.804.9646 (cell)
> 410.744.5355(FAX)
> http://www.jonysolutions.com

Current Thread