[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XPath 2.0 Best Practice Issue: Graceful Degradation

  • From: "Andrew Welch" <andrew.j.welch@g...>
  • To: "James Fuller" <james.fuller.2007@g...>
  • Date: Wed, 30 Jan 2008 10:37:57 +0000

Re:  XPath 2.0 Best Practice Issue: Graceful Degradation
On 29/01/2008, James Fuller <james.fuller.2007@g...> wrote:
> though doesn't schema-element() have
> something to do with substitution groups ?

It does, for example:

<xsl:stylesheet
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

    <xsl:import-schema>
        <xs:schema>
            <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:sequence>
                    <xs:any maxOccurs="unbounded"/>
                </xs:sequence>
            </xs:complexType>

        </xs:schema>
    </xsl:import-schema>

    <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>
        </shapes>
    </xsl:variable>

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

</xsl:stylesheet>


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)"/>

with:

<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.



cheers
-- 
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/


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


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.