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

Re: using step or following-sibling?

Subject: Re: using step or following-sibling?
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 03 Dec 2004 17:17:41 -0500
xsl sibling next
Matt,

At 04:00 PM 12/3/2004, you wrote:
Let's say I have the following XML:


<top> <results> <row> <emp_nm>Bill Smith</emp_nm> </row> <row> <emp_nm>Sue Johnson</emp_nm> </row> <row> <emp_nm>Matt Keller</emp_nm> </row> </results> </top>

Okay.


And in my xsl I have a template like this:

<xsl:template match="/top/results/row">
<p>I like <xsl:value-of select="emp_nm"/> and I also like his or her follower, MY TROUBLE ZONE</p>
</xsl:template>


------------------

How in the world do I replace MY TROUBLE ZONE with the value of "emp_nm" in the following row? Not all following roles, just the very next row. And how can I do it w/out using position()?

I assume you're not asking how to substitute the string. (If you are, replacing the string "MY TROUBLE ZONE" with any value at all will require some string-substitution magic, which you can find documented in the FAQ. XSLT does not excel at string manipulation but it's not impossible to do either. If you could arrange for this placeholder to be an element or a processing instruction instead of a string, your processing would be both easier and more robust.)


As to the value you want to substitute, if your context node is the row, the emp_nm of the very next row is expressed in XPath as "following-sibling::row[1]/emp_nm. While this does use position() (the predicate expands to [position()=1]), in XSLT were you to say

<xsl:value-of select="following-sibling::row/emp_nm"/>

you would get the value only of the next one, since the value-of instruction returns a string, and the rule for converting a node-set into a string is to take the string value of the first node in the node-set (which happens to be the one you want).

If there is no such following sibling, of course, nothing will get substituted.

I hope this helps,
Wendell


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================

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.