This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: FW: Path Reversal
- From: "Andrew Welch" <andrew at thebristoldirectory dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Tue, 29 Jan 2002 12:47:13 -0000
- Subject: RE: [xsl] FW: Path Reversal
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi,
I know there have been a few goes at this, but I thought I would do one as
well :)
This stylesheet recursively extracts each word of the path (the bits in
between the slashes) and then when its at the final word, selects the
content of the node using '//'.
It may help, i dunno....
==stylesheet==
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:call-template name="text_wrapper">
<xsl:with-param name="Text" select="'/funstuff/jokes/veryfunnyjoke'"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="text_wrapper">
<xsl:param name="Text"/>
<xsl:choose>
<xsl:when test="contains($Text,'/')">
<xsl:call-template name="text_wrapper">
<xsl:with-param name="Text" select="substring-after($Text,'/')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="//node()[@name=$Text]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
==input==
<?xml version="1.0"?>
<root>
<node name="funstuff">
<node name="jokes">
<node name="veryfunnyjoke">the joke</node>
</node>
</node>
</root>
==output==
<?xml version="1.0" encoding="utf-8"?>the joke
cheers
andrew
===
-----Original Message-----
From: owner-xsl-list@lists.mulberrytech.com
[mailto:owner-xsl-list@lists.mulberrytech.com]On Behalf Of Alek Andreev
Sent: Monday, January 28, 2002 2:18 PM
To: xsl-list@lists.mulberrytech.com
Subject: [xsl] FW: Path Reversal
Hi!
Suppose I have the following piece of XML:
<node name="funstuff">
<node name="jokes">
<node name="veryfunnyjoke"/>
</node>
</node>
I have a path (as a string) which is composed of the @names of the
nodes. It looks like /funstuff/jokes/veryfunnyjoke. How can I write a
template (or an EXSLT function) that returns the node the path points to
(e.g. veryfunnyjoke)?
Regards,
Alek Andreev
alek@post.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list