简体   繁体   中英

How xslt 2.0 is variable with key value attribute is different from xslt 3.0 map? Which one will perform faster?

**In XSLT 2.0 ** I am using it like this:

Declaring a variable

    <xsl:variable name="map">
        <entry parent="false" type="DateTime"  key="MKR_DT"          class="Base"             maprule="primarykey">lastUpdatedDate</entry>
        <entry parent="false" type="String"    key="POA_ADD_1"       class="AddressType"      maprule="primarykey-AddressType__Home Address">address1</entry>
<entry parent="false" type="String"    key="POA_ADD_2"       class="AddressType"      maprule="primarykey-AddressType__Home Address">address2</entry>
<entry parent="false" type="String"    key="POA_ADD_3"       class="AddressType"      maprule="primarykey-AddressType__Home Address">address3</entry>
<entry parent="false" type="String"    key="POA_ADD_4"       class="AddressType"      maprule="primarykey-AddressType__Home Address">address4</entry>
    </xsl:variable>

Using it to get value like this

<xsl:for-each select="x:ROW_LCR/x:new_values/x:new_value">
 <xsl:variable name="columnname" select="x:column_name">
 <xsl:if test="$map/entry[@key=$columnname]>
  //some code here
 </xsl:if>
</xsl:for-each>

Now say if I go with xslt 3.0, how much changes will be required with respect to xslt 2.0 and if I am using map from xslt 2.0 is it more efficient than what I am using now?

A few observations.

(1) An XSLT 2.0 processor may or may not optimize your key lookup expression $map/entry[@key=$columnname] to use some kind of index or hash table based on the value of $columnname. (For example, Saxon-HE will do a serial search, but Saxon-EE will use an index). If you want a better chance of this being fast (assuming hundreds of entries to search) then you're best off using xsl:key and the key() function rather than a simple filter expression.

(2) Any sensible implementation of maps in XSLT 3.0 is going to use some kind of index or hash mechanism to provide fast access by key. It might well be the same mechanism as xsl:key and the key() function use, and will probably have similar performance. The chief reason to use maps in preference to xsl:key and key() is not performance, but flexibility: for example the things you are indexing with xsl:key have to be nodes, and they have to be nodes within a single document, but maps have no such restriction.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM