I have an XML document in the following format:
<Contents>
<Content Name="ClientXML">
<EntityData>
<Data Name="EQ_EligibleForGuaranteedIssue">Yes</Data>
<Data Name="ABRInd">NO</Data>
<Data Name="AC_AgentNo">12345</Data>
<Data Name="AC_AgentPersonallyMetWithApplicant">Has</Data>
<Data Name="AC_City">Pomona</Data>
<Data Name="AC_FirstName">Kimmy</Data>
<Data Name="AC_FullName">Kimmy N Jackson</Data>
<Data Name="AC_Initials">K J</Data>
<Data Name="AC_LastAndSuf">Jackson</Data>
...
</EntityData>
</Content>
<Content Name="UserXML">
<EntityData>
<Data Name="TransRefGUID">789-456-123456789-456</Data>
...
</EntityData>
</Content>
</Contents>
Other information:
I have to create an XSL transform and am using the xsl:value-of select="..." function. My question is, what XPath expression is going to execute the fastest? For example
<xsl:value-of select="\\Contents\Content[@Name="ClientXML"\EntityData\Data[@Name=".."]">
or simply
<xsl:value-of select="\\Data[@Name=".."]">
I don't have access to the end server which will eventually run this process, and locally the second option may appear to be a little faster.
Wondering if anyone has an opinion, and on a much larger scale if one may be faster.
Thanks!
Using keys in XSLT will be far faster than an XPath expression, especially one with //
which can be very slow to execute and should only be used when necessary.
<xsl:key match="Content" use="@Name" name="MyContentsLookup"/>
...
<xsl:value-of select="key('MyContentsLookup','ClientXML')"/>
An XSLT processor can implement internal search mechanisms to quickly look up a value in tens of thousands of entries, far faster than with XPath.
I've published an overview of XSLT keys here: http://www.CraneSoftwrights.com/resources/xslkeys/index.htm