[Home] [By Thread] [By Date] [Recent Entries]

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

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]


Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member