[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
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! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|