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

Re: processing alternating sibling nodes

Subject: Re: processing alternating sibling nodes
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 31 Dec 2002 16:20:35 -0500
wendell tobias
Steve,

The trouble is here:

At 03:38 PM 12/31/2002, you wrote:
>               <xsl:for-each select="descendant::question">
>                       <xsl:value-of select="text"/>
>                       <xsl:value-of select="reference"/>
>               </xsl:for-each>

Since you have a single <question> descendant of the context node, the context shifts to that; the stylesheet then puts out values of the sets of "text" element children (select="text") and reference children (select="reference").


However, the 'value-of' instruction you are using explicitly pulls out a string value; since the string value of a set of nodes is defined (in XPath 1.0) as the string value of the first node in the set (in document order), that's what you're getting: your first <text> followed by the first <reference>.

I'd suggest junking the for-each instruction (it's doing nothing but changing the context node) and instead saying in its place,

<xsl:apply-templates select="question/text"/>

which tells the processor to process (by applying templates to) *all* the <text> children of the <question> children of the context node. Then write another template for the text, as in

<xsl:template match="text">
  <xsl:value-of select="."/>
  <xsl:value-of select="following-sibling::reference[1]"/>
</xsl:template>

This time, for each text node its own value is reported (a string value of a node set with one member: no problem), and then the value of its next following reference element is reported.

The logic here assumes you have a straight text/reference/text/reference sequence of simple pairs (no helpful wrappers). You will need to qualify it further if your data is not so regular.

(Of course this could also be done within your for-each if you really wanted.)

I hope that 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 ======================================================================


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.