Performance observation.
Ihe Onwuka <[email protected]> Tue, 8 Sep 2020 03:16:47 -0400
| Newsgroups | gmane.text.xml.saxon.help,gmane.text.xml.xsl.general.mulberrytech |
|---|---|
| Message-ID | <CALfs7+yB=TRX6CggueBwK_wH8mgp_TpkmehOyymjTz4=WpGAtA@mail.gmail.com> |
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
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/
[email protected]
https://lists.sourceforge.net/lists/listinfo/saxon-help