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

Re: getting the last value of a nodeset

Subject: Re: getting the last value of a nodeset
From: James Fuller <jim.fuller@xxxxxxxxxxxxxx>
Date: Sun, 06 Feb 2005 14:05:25 +0100
xsl last value
Prasad Akella wrote:

hi

I am sorry i do not want to evaluate the xpath expression. i would like to have the last segment of the xpath statement as i would be using that same string to name a control in my xhtml page. thus a control in an xhtml page and the node in an xml document would be matched and i can put the value thus entered from the user browser into the respective tag. thus i have to get the last string which represents a node in an xml document and name an xhtml control with the same. i hope i am clear

with regards,
Prasad


aha, sorry didnt mean to change your question....sometimes folks get confused

this is easier.....u need a tail like function

TEST XML

<?xml version="1.0" encoding="UTF-8"?>
<test xmlns:xforms='http://www.example.org/xforms'>

<xforms:bind nodeset="/Exam/ExamMetaData/Title"/>

</test>


TEST XSLT


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version = '1.0'
 xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
 xmlns:xforms='http://www.example.org/xforms'>

<xsl:output method="xml" indent="yes" />

<xsl:variable name="variable" select="/test/xforms:bind/@nodeset"/>

<xsl:template match="/">

nodeset: <xsl:value-of select="$variable"/>

 last segment name: <xsl:call-template name="tail">
   <xsl:with-param name="string" select="$variable"/>
 </xsl:call-template>

</xsl:template>

<xsl:template name="tail">
<xsl:param name="string" select="."/>
<xsl:choose>
<xsl:when test="substring-after($string,'/')">
<xsl:call-template name="tail">
<xsl:with-param name="string" select="substring-after($string,'/')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>



</xsl:stylesheet>



should result in printout of nodeset value and last segment value


if you want to reuse then just wrap call template in a variable;


<xsl:variable name="desiredresult">


<xsl:call-template name="tail">
   <xsl:with-param name="string" select="$variable"/>
 </xsl:call-template>

</xsl:variable>

though be careful with whitespace....

gl, Jim Fuller

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.