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

How to execute an expression XPATH in String

Subject: How to execute an expression XPATH in String
From: CAO Tuan Dung <Tuan-Dung.Cao@xxxxxxxxxxxxxxx>
Date: Mon, 17 Jun 2002 11:47:54 +0200
xsl value of select
Hi all the experts,

I'm a beginner in XSLT and i'm meet some problem so difficult.

I have an webpage XHTML and I want to extract all the value at address XPATH as:
/html/body/table/tr[1]/td[2]/p
/html/body/table/tr[1]/td[3]/p
/html/body/table/tr[1]/td[4]/p ...... and so on
as well as /html/body/table/tr[2]/td[2]/p /html/body/table/tr[3]/td[2]/p
......


so i write a template with 3 parameter: $path: for an expression XPATH
$tag: for the tag at which the index change repeatly as: TR, TD, p, a, Table,..
$index: for the index to change.
and call the template recursively. <xsl:template name="GetAllValue">
<xsl:param name="path" />
<xsl:param name="tag" />
<xsl:param name="index" />
<xsl:variable name= "tagindex" select "concat($tag,'[',$index,']')" />
<xsl:variable name="titi" select= "xalan:evaluate(concat(substring-before($path,$tagindex),$tagindex,substring-after($path,$tagindex)))"/>


<xsl:choose>
<xsl:when test="string-length($titi) = 0" />
<xsl:otherwise>
<Value>
<xsl:value-of select="$titi" disable-output-escaping="yes"/>
</Value> <xsl:call-template name= "GetAllValue">
<xsl:with-param name="path" select="$path"/>
<xsl:with-param name="path" select="$tag"/>
<xsl:with-param name="index" select="$index+1"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>oose>
</xsl:template>


and i call template
<xsl:template match="/">
<HTML>
<BODY>
<xsl:call-template name= "GetAllValue">
<xsl:with-param name="path" select="'/html/body/table/tr/td[1]/font/a'" />
<xsl:with-param name="tag" select=" 'td' " /> <xsl:with-param name="index" select="1"/>
</xsl:call-template>
</BODY>
</HTML>
</xsl:template>sl:template>


because i have to using concat function to calcule new address after each template call, so i have use value XPATH as String and use xalan:evaluate


but when i run this XSL i meet always error: Call to extension function failed: http://xml.apache.org/xalan


How to solve this problem, can we avoid to use String? Please help me if you have any idea.

Best wish.





XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list


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-2013 All Rights Reserved.