[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Evaluate XPath from String

Subject: Evaluate XPath from String
From: James Cummings <james@xxxxxxxxxxxxxxxxx>
Date: Fri, 5 Jun 2009 17:55:04 +0100
 Evaluate XPath from String
Hi there.

I'm wondering about processing strings as XPaths in XSLT2.  I know
about saxon:evaluate() but what I'm wondering is a way to do this in
XSLT2 _without_ extensions.  (A possible answer is "don't do it, way
too hard, just use the extensions".)

So if I was using saxon:evaluate() I might do something like:
====input===
<?xml version="1.0" encoding="UTF-8"?>
<foo>
    <paths>
        <path>/foo/blort/wibble[1]</path>
        <path>/foo/blort/wibble[2]</path>
         <path>//*[@xml:id='wibNum2']/splat/@att</path>
    </paths>
    <blort>
        <wibble>test text 1</wibble>
        <wibble>Another wibble </wibble>
        <wibble xml:id="wibNum2">This is <splat att="value1">a
test</splat></wibble>
    </blort>
    </foo>
====

and a script like:

====xsl===
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      version="2.0" xmlns:saxon="http://saxon.sf.net/"
exclude-result-prefixes="#all">
<xsl:output indent="yes"/>
<xsl:template match="/foo">
    <foo>
        <xsl:for-each select="paths/path">
        <out><xsl:value-of select="saxon:evaluate(.)"/></out>
    </xsl:for-each>
        </foo>
</xsl:template>

</xsl:stylesheet>
====

I should get the output:

====output===
<?xml version="1.0" encoding="UTF-8"?>
<foo>
   <out>test text 1</out>
   <out>Another wibble </out>
   <out>value1</out>
</foo>
====

Hurrah, it works.  But I guess my question is how hard is it to create
fn:myEvaluate() in XSLT2 which does basically the same thing?

Thanks for any suggestions.

-James

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.