Subject: [xsl] Here’s how to query an XML Schema that consists of many files From: "Roger L Costello costello@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Thu, 19 Oct 2023 13:07:25 -0000 |
Hi Folks, I have a large, complex XML Schema which is spread across dozens of files. While the use of multiple files is a nice divide-and-conquer strategy for organizing the schema, it can make queries challenging. For example, today I needed to find out what elements are declared to be of a type that is abstract, i.e., elements with an abstract type. One approach to solving this problem would be to manually examine each schema file, jot down the names of each complexType with abstract="true", and then examine each file again to find which elements have one of those types. As I mentioned, my schema has lots of files, so this approach is not reasonable. The folks at Saxonica have created a tool which analyzes all the schema files and outputs a single file that contains an XML-formatted summary of the content of the files. The Saxonica folks call this file the Schema Component Model, scm. Heres how I created a Schema Component Model for my XML Schema: 1. First, of course, I downloaded Saxon (https://www.saxonica.com/download/download_page.xml) 2. Next, I opened a command window and changed directory to where my schema files are located 3. Lastly, I typed this at the command window: java com.saxonica.Validate -export:arinc.scm -xsd:Records/AeroPublication.xsd In my case, the main schema file is named AeroPublication.xsd, which is in the Records folder. The result of running the command is Saxon generated a file named arinc.scm which, as I said, contains an XML-formatted summary of the content of all the files. Now I can query the scm file and obtain just about any information I desire. Recall that I need to find all the elements with an abstract type. I wrote an XSLT program to query the scm file for that information. Below I show the XSLT program. Nice! <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:scm="http://ns.saxonica.com/schema-component-model" exclude-result-prefixes="#all" version="3.1"> <xsl:output method="xml"/> <xsl:template match="/"> <elements-with-abstract-type> <xsl:for-each select="scm:schema/scm:complexType[@abstract eq 'true']"> <xsl:variable name="name-of-absract-complexType" select="@name"/> <xsl:variable name="id-of-absract-complexType" select="@id"/> <record> <abstract-complexType> <xsl:value-of select="$name-of-absract-complexType"/> </abstract-complexType> <elements-with-that-type> <xsl:for-each select="/scm:schema/scm:element[@type eq $id-of-absract-complexType][@abstract eq 'false']"> <element> <xsl:value-of select="@name"/> </element> </xsl:for-each> </elements-with-that-type> </record> </xsl:for-each> </elements-with-abstract-type> </xsl:template> </xsl:stylesheet>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] [ANN] Version 26 of the Oxyge, Octavian Nadolu octa | Thread | Re: [xsl] Here’s how to query an X, Martin Honnen martin |
[xsl] [ANN] Version 26 of the Oxyge, Octavian Nadolu octa | Date | Re: [xsl] Here’s how to query an X, Martin Honnen martin |
Month |