Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: XSLT evaluate XPath from a string

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 8/20/2008 1:05:00 PM

Mycroft wrote:

> I have tried using code from EXSLT but that has not worked and everything I 
> read suggests that XSLT 2.0 might have a method to perform this operation, 
> but I find no examples.

Saxon 9 is the current Saxon version that implements XSLT and XPath 2.0. 
It has
http://www.saxonica.com/documentation/extensions/functions/evaluate.html
and
http://www.saxonica.com/documentation/extensions/functions/evaluate-node.html
so with your sample XML corrected to (you had 'type' instead of '@type' 
which does not find anything)

<library>
	<books>
		<book title="A" type="science fiction"/>
		<book title="B" type="fantasy"/>
		<book title="C" type="romance"/>
		<book title="D" type="science fiction"/>
		<book title="E" type="Christianity"/>
	</books>
	<librarian>
		<defaultXPath>//book[@type="Christianity"]</defaultXPath>
	</librarian>
</library>

and a stylesheet with

<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:saxon="http://saxon.sf.net/"
   exclude-result-prefixes="saxon"
   version="2.0">

   <xsl:template match="/">
     <xsl:apply-templates 
select="saxon:evaluate-node(library/librarian/defaultXPath)"/>
   </xsl:template>

   <xsl:template match="book">
     <xsl:copy-of select="."/>
   </xsl:template>

</xsl:stylesheet>

the output is

<?xml version="1.0" encoding="UTF-8"?><book title="E" type="Christianity"/>


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent