OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] XPath 2.0 Best Practice Issue: Graceful Degradation

On 29/01/2008, James Fuller <james.fuller.2007@gmail.com> wrote:
> though doesn't schema-element() have
> something to do with substitution groups ?

It does, for example:

    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0">

            <xs:element name="shapes" type="shapes"/>
            <xs:element name="shape" type="xs:string"/>
            <xs:element name="square" substitutionGroup="shape"/>
            <xs:element name="circle" substitutionGroup="shape"/>
            <xs:element name="triangle" substitutionGroup="shape"/>

            <xs:complexType name="shapes">
                    <xs:any maxOccurs="unbounded"/>


    <xsl:variable name="input">
        <shapes xsl:type="shapes">
            <square>I'm a square</square>
            <circle>I'm a circle</circle>
            <triangle>I'm a triangle</triangle>

    <xsl:template match="/" name="main">
        <xsl:value-of select="$input//schema-element(shape)"
separator=", "/>


Produces this output:

I'm a square, I'm a circle, I'm a triangle

Or you could do:

<xsl:apply-templates select="$input//schema-element(shape)"/>


<xsl:template match="schema-element(shape)"> [default] </xsl:template>
<xsl:template match="circle" priority="2"> specific </xsl:template>

to get:

[default]  specific  [default]

I haven't used this is in real life yet, but I can see the benefits of
effectively coupling to the substitution group instead of the actual
elements.  I can also see the drawbacks of requiring the input to be
validated every time if it doesn't change.

Andrew Welch
Kernow: http://kernowforsaxon.sf.net/

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS