[xslt] Using XSLT as a query engine




I have created a large XML File (2.6 MB) and would like to query it to find the
element with a particular attribute.  The attribute is unique in the file.  I
have also created the following XSLT file:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
<xsl:param name="param1"/>
<xsl:param name="param2"/>

<xsl:key name="Id-key" match="/DocRoot/Element" use="@id"/>
<xsl:template match="/">
   <xsl:copy-of select="key('Id-key',$param1)"/>
   <xsl:copy-of select="key('Id-key',$param2)"/>
</xsl:template>

</xsl:stylesheet>


I have two questions:

1) I must be misunderstanding how to use xsl:copy-of because only the element
with the id attribute matching $param1 is output.

2)Can I tell libxslt to build the key only once so I can apply the stylesheet
with new parameters and not have to take the performance hit to rebuild the key
for an unchanged document?

Thank you very much for this excellent library!





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]