|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: dynamic XPath?
[Yue Ma] > This could be a dumb question: > Is there a way we can evaluate a dynamic XPath like: > <xsl:if test="$tagPath = 'actual value'"> > The tagPath is something like "//root/tag1/tag2" > > Seems we can not do it with XSLT 1.0, right? > Yes we can, depending on how complicated you want the path expression to be. Here is an example - XML source - <root> <e1>This is e1</e1> <e2>This is e2</e2> </root> ========================= Stylesheet - <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- Path to test against --> <xsl:variable name='tagPath' select='"/root/e2"'/> <xsl:template match="/root/*"> <!-- Create a variable to hold a current path expression --> <!-- Standard expression to create a string for the path of the current node --> <xsl:variable name='path'> /<xsl:for-each select="ancestor::*"> <xsl:value-of select="name()" />/</xsl:for-each><xsl:value-of select = "name()" /> </xsl:variable> <!-- Test the expression --> <xsl:if test='normalize-space($path)=$tagPath'>Got path for <xsl:value-of select='name()'/></xsl:if> </xsl:template> </xsl:stylesheet> Cheers, Tom P XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








