[xsl] Re: [saxon] Performance observation.

Subject: [xsl] Re: [saxon] Performance observation.
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 8 Sep 2020 10:19:07 -0000
I'm slightly suprised by the performance effect but it depends how often the
pattern is matched, and what other patterns are present in the stylesheet.
Certainly putting complex logic into patterns can be risky from a performance
point of view.

How about using xsl:where-populated rather than xsl:try?

Michael Kay
Saxonica

> On 8 Sep 2020, at 08:16, Ihe Onwuka <ihe.onwuka@xxxxxxxxx> wrote:
>
> The goal is to create a namespace node if the value of xsi:type is a QName.
>
> The code here simulates the situation
>
> https://xsltfiddle.liberty-development.net/a9HjZj
<https://xsltfiddle.liberty-development.net/a9HjZj>
>
> The problem is that this fails if the select evaluates to the empty string.
>
>  <xsl:template match="@xsi:type">
>          <xsl:namespace name="{substring-before(.,':')}"
select="$schemas/thing/@targetNamespace"/>
>          <xsl:next-match/>
>    </xsl:template>
>
> Now in the real code the select is actually a key retrieval so looks more
like this
>
>    <xsl:template match="@xsi:type">
>          <xsl:namespace name="{substring-before(.,':')}"
select="key('myKey',.,$schemas)/@targetNamespace"/>
>          <xsl:next-match/>
>    </xsl:template>
>
> So in order to avoid failure I tried this
>
>      <xsl:template match="@xsi:type[
key('myKey',.,$schemas)/@targetNamespace => normalize-space()]">
>          <xsl:namespace name="{substring-before(.,':')}"
select="key('myKey',.,$schemas)/@targetNamespace"/>
>          <xsl:next-match/>
>    </xsl:template>
>
> now that works but quadrupled the execution time of the stylesheet.
>
> Doing it with try catch
>
>       <xsl:template match="@xsi:type">
>          <xsl:try>
>              <xsl:namespace name="{substring-before(.,':')}"
select="key('myKey',.,$schemas)/@targetNamespace"/>
>              <xsl:catch/>
>          </xsl:try>
>          <xsl:next-match/>
>    </xsl:template>
>
> is a teenie bit quicker.
>
> Overall execution time is still tolerable so posting this as an
observation.
>
> For the  XSL list
>
> Is there a way to code
>
>    <xsl:template match="@xsi:type[ key('myKey',.,$schemas)/@targetNamespace
=> normalize-space()]">
>          <xsl:namespace name="{substring-before(.,':')}"
select="key('myKey',.,$schemas)/@targetNamespace"/>
>          <xsl:next-match/>
>    </xsl:template>
>
> without repeating the code for the key access thats on the template rule
predicate inside the template rule.
>
>
>
>
>
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> saxon-help@xxxxxxxxxxxxxxxxxxxxx
> https://lists.sourceforge.net/lists/listinfo/saxon-help

Current Thread