|
Subject: RE: [xsl] Custom function in template match predicate From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Tue, 23 Sep 2008 23:07:36 +0100 |
Not sure why you are writing a custom function when resolve-QName already
exists to do this job.
If your code was schema-aware, of course, the QName resolution would happen
automatically:
<xsl:template match="schema-element(foo)[@format eq QName('fmt:type1')]">
As Wendell pointed out, the reason it doesn't work is the "= true".
Michael Kay
http://www.saxonica.com/
> -----Original Message-----
> From: Ian Stokes-Rees [mailto:ijstokes@xxxxxxxxxxxx]
> Sent: 23 September 2008 18:19
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Custom function in template match predicate
>
> Hi,
>
> I currently have some very unwieldy predicates showing up in
> lots of xsl:template/@match statements, of the form:
>
>
> <xsl:template match="
> foo[ substring-after(./@format,':') = 'type1' and
> namespace-uri-for-prefix(substring-before(./@format,':'),.)
> = 'http://example.com/schemas/formats' ]">
>
>
> which aim to match different <foo> elements based on the
> @format QName
> value, e.g.:
>
>
> <table xmlns:fmt='http://example.com/schemas/formats'>
> <foo format="fmt:type1">2008-09-23</foo>
> <foo format="fmt:type2">9/23/08</foo>
> </table>
>
>
> and which do QName expansion so the user can choose the prefix.
>
> I would like to replace the "match" statement with a
> simplified custom
> function of the form:
>
>
> <xsl:template match="foo[ my:test('type1',.) = true ]">
>
>
> where my:test is defined as:
>
>
> <xsl:function name="my:test">
> <xsl:param name="fmtcode"/>
> <xsl:param name="context"/>
>
> <xsl:choose>
> <xsl:when test="substring-after($context/@format,':') =
> $fmtcode and
>
> namespace-uri-for-prefix(substring-before($context/@format,':'
> ),$context)
> = 'http://example.com/schemas/formats' ">
> <xsl:value-of select="boolean(1)"/>
> </xsl:when>
> <xsl:otherwise>
> <xsl:value-of select="boolean(0)"/>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:function>
>
>
> The problem is, this doesn't work with Saxon8B. Would others expect
> this to work with different XSLT v2.0 processors? Is there
> some way to
> get this to work with Saxon8B?
>
> Cheers,
>
> Ian
>
> --
> Ian.Stokes-Rees@xxxxxxxxxxxx +1 (617) 418-4168
> SP Metric Limited, Technology Consulting
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Custom function in templa, Ian Stokes-Rees | Thread | Re: [xsl] Custom function in templa, Ian Stokes-Rees |
| RE: [xsl] trying to exclude result , Michael Kay | Date | [xsl] Xsl:strip-space and xsl:prese, Pankaj Chaturvedi |
| Month |