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

RE: FW: Path Reversal

Subject: RE: FW: Path Reversal
From: "Andrew Welch" <andrew@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 29 Jan 2002 12:47:13 -0000
jokes about name andrew
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@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Alek Andreev
Sent: Monday, January 28, 2002 2:18 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  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@xxxxxxxx



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



 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.