Re: [xsl] Schema Exploration...

Subject: Re: [xsl] Schema Exploration...
From: "Mark R. Diggory" <mdiggory@xxxxxxxxxxxxxxxxx>
Date: Sat, 20 Apr 2002 22:43:10 -0400



Having a canonical representation, in particular with groups and derivations resolved (or ignored), it becomes easier to create the key. You can create a key that combines the name that you're looking for with the element (or complex type) in which it's contained. For example if you're adopting a "Russian Doll" style, where all complex types are anonymous and elements are all nested inside each other, you can use the following:

<xsl:key name="elements-by-parent-element"
 match="xs:element//xs:element"
 use="concat(ancestor::xs:element[1]/@name, '//' (@name | @ref))" />

Ok, yes, I took this approach and defined a key like yours only with the match selection I got from Wendell.

<xsl:key name="elements-by-parent-element" match="xs:schema/xs:element | xs:element/xs:element | xs:element/xs:complexType/xs:choice/xs:element | xs:element/xs:complexType/xs:sequence/xs:element | xs:element/xs:complexType/xs:element" use="concat(ancestor::xs:element[1]/@name, '//', (@name | @ref))"/>

Yes, I'd like to come up with a simpler match pattern that gets all the possiblities for xs:elements. Plus, I want to do some similar keys for attributes-by-parent-element.

So Far the closest I've been able to come is:

<xsl:variable name="my_snode" select="($parent_snode/descendant::xs:element)[@name=$node_name or @ref=$node_name]"/>

Unfortunately, I don't think this will exclude cases where the "child" xs:element (its not really a child, I know) isn't really a "1st" descendant. 1st descendant meaning, there are no xs:elements between it and the "parent" xs:element (its not really a parent, I know).

So I was try something like this, but I can't get the syntax right:
		
<xsl:variable name="my_snode" select="($parent_snode/descendant::xs:element/*[ancestor::xs:element[@name=$parent_snode/@name]][1] )[@name=$node_name or @ref=$node_name]"/>


Each xs:element that occurs within another xs:element is indexed by a combination of its closest ancestor xs:element's name and its own name or ref attribute. For example, to find all the elements called 'foo' nested inside elements called 'bar', you could use:

key('elements-by-parent-element', 'bar//foo')

I have a good example going now with this approach. It works very well for the schema I've been working with. Here's a demo site (Don't expect it will stay there forever.)

http://vdc.fas.harvard.edu:8080/Editor/index.htm (Look under Project 2)

Its a little slow due to some server side buffering I need to resolve, but it works.

The XSL and schema are provided as well.

-Mark


(The other thing that you'll have to tackle some point in the future
is namespace resolution of the 'ref' attributes.)


gulp




XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread