xsl-list
[Top] [All Lists]

[xsl] Re: [saxon] Performance observation.

2020-09-08 05:19:15
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(_dot_)onwuka(_at_)gmail(_dot_)com> 
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(_at_)lists(_dot_)sourceforge(_dot_)net
https://lists.sourceforge.net/lists/listinfo/saxon-help
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>
  • [xsl] Re: [saxon] Performance observation., Michael Kay mike(_at_)saxonica(_dot_)com <=