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

Re: dynamic XPath?

Subject: Re: dynamic XPath?
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Wed, 12 Mar 2003 22:11:44 +0100
xsl dynamic xpath
"Passin, Tom" <tpassin@xxxxxxxxxxxx> wrote in message
news:5D3C2276FD64424297729EB733ED1F76AF95BB@xxxxxxxxxxxxxxxxxxxxxx
> [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.

This is quite exaggerated. See below.

> 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>

What is so "standard" about this expression? It does not uniquely identify
the node -- so it should not qualify as an acceptable solution.


>
> <!-- Test the expression -->
> <xsl:if test='normalize-space($path)=$tagPath'>Got path for
> <xsl:value-of select='name()'/></xsl:if>
> </xsl:template>
>
> </xsl:stylesheet>


This comparison will work in rare cases and will not work in general if
$tagPath evaluates to a single node having preceding siblings.

It will also "work" for more than one node (in case $tagPath evaluates to a
nodeset of two or more nodes) and most probably is not what the author of
the original message wanted.



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL




 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.