This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Schema Exploration...


Mark,

At 02:07 PM 4/18/2002, you wrote:
>I'm trying to select a schema element node relative to the current 
>xs:element node I've referenced in a parameter ($schema_node). The problem 
>is that there are several cases that need to be checked for:
>
>xs:element/*[@name='test1a' or @ref='test1b']
>xs:element/xs:complexType/xs:choice/*[@name='test2a' or @ref='test2b']
>xs:element/xs:complexType/xs:sequence/*[@name='test3a' or @ref='test3b']

You can take advantage of the fact that your schema should not have 
xs:elements with *both* a @name and a @ref to do something like:

<xsl:variable name="okaynames" select="'test1a test1b test2a test2b test3a 
test3b'"/>
<!-- the variable is not strictly necessary but makes things easier -->
<xsl:apply-templates select=".//xs:element[contains($okaynames, 
(@name|@ref))]"/>

If I understand your problem correctly, this will work because:

.//xs:element selects all xs:element descendants of the current node 
(*really* strictly, all xs:element children of nodes on the 
descendant-or-self axis from the current node). If your element 
declarations go down more than one level, you may have to be more specific 
with this step, as in  select="(xs:element | 
xsl:complexType/xs:choice/xs:element | 
xs:complexType/xs:sequence/xs:element)[ ... the predicate ... ]"

The predicate [contains($okaynames, (@name|@ref))] tests true if the value 
of the @name or @ref attribute of the selected node (whichever is first -- 
up to your processor since they're attributes -- but there should be only 
one) is contained in the string $okaynames.

If you wanted to be *really* fancy you could set something like:

<xsl:variable name="okaynames" select="concat(concat(local-name(), 'a'), ' 
', concat(local-name(), 'b'))"/>

which makes the string "test1a test1b" for element test1, "test2a test2b" 
for element test2, etc. (Junk this bit if these aren't actually your 
element names.)

The space ' ' makes a good delimiter in this test string since it's not 
allowed inside a legal element name.

We'll trust Mike K., Jeni or anyone else (go to it, gang!) to spot any 
conceptual errors or omissions I've made here.

I hope that helps--
Wendell



======================================================================
Wendell Piez                            mailto:wapiez@mulberrytech.com
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
   Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]