xsl-list
[Top] [All Lists]

Re: [xsl] XPath function for <xsl:apply-templates/>?

2013-11-18 09:48:11
It's not very difficult to add to your stylesheet:

<xsl:function name="f:apply-templates">
  <xsl:param name="node" as="node()*/>
  <xsl:apply-templates select="$node"/>
</xsl:function>

and if you define one such function for each declared mode, then in 3.0 you can 
use dynamic function invocation to select a mode dynamically.

Michael Kay
Saxonica


On 18 Nov 2013, at 14:25, Christian Mahnke 
<cmahnke(_dot_)sub(_at_)googlemail(_dot_)com> wrote:

Hi,
I’ve noticed the problem with the dynamic mode setting as well. Maybe these 
can be points for improvement in the next version of the XSLT specification:
* dynamic mode
* function like shortcut for apply-templetes

Thanks,
Christian




Am 18.11.2013 um 15:19 schrieb David Carlisle 
<davidc(_at_)nag(_dot_)co(_dot_)uk>:

On 18/11/2013 14:11, Christian Mahnke wrote:
Hi,
might have been asked here before but is there some XPath function that 
works like <xsl:apply-templates/>?
This would be good for readability. I’ll give you an example, currently I 
do this:

                       <xsl:variable name="content">
                           <xsl:apply-templates mode="filter"/>
                       </xsl:variable>
                       <xsl:copy-of select="a18:field('place', $content)“/>

What I’am asking for would look like this:

                       <xsl:copy-of select="a18:field('place', 
apply-templates('filter'))“/>


Any thoughts?
There is probably an extension for this.

Best,
Christian

xmlns:f="data:,f"

well making mode a parameter in general is harder as it's a compile time 
constant in the normal syntax, but for a fixed mode you can doe

<xsl:function name="f:apply-templates-filter">
<xsl:param name="seq"/>
<xsl:apply-templates mode="filter" select="$seq"/>
</xsl:function>


  <xsl:copy-of select="a18:field('place', f:apply-templates-filter(node())“/>

Note you can't have an implicit default context in user defined functions so 
you need to pass in the sequence node() explicitly.

David


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



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



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