xsl-list
[Top] [All Lists]

Re: [xsl] Avoiding boneheaded mistakes in XSLT?

2010-12-30 11:47:36
As a use case I'm trying to catch typos and other 'man made'
errors. How might a transformatron catch those?

Two defensive techniques are:

1. Use the as attribute on your template:

<xsl:template match="foo" as="element(p)">
  <xsl:apply-templates select="/foo/bar"/>
</xsl:template>

If the apply-templates call doesn't result in a <p> (for whatever
reason) then you will get an error.

2. Use a variable with the as attribute:

<xsl:variable name="bar" select="/foo/bar" as="element(bar)"/>

If the variable doesn't select a bar element, then you'll get an error.

Ultimately though, the best defense is result validation and a tight schema.


-- 
Andrew Welch
http://andrewjwelch.com

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--