[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: "Wright, Steve" <Steve.Wright@xxxxxxx>
Date: Tue, 31 Dec 2002 18:31:33 -0500
instruction of alternating
That did the trick! Thanks Wendell. 
-steve

-----Original Message-----
From: Wendell Piez [mailto:wapiez@xxxxxxxxxxxxxxxx]
Sent: Tuesday, December 31, 2002 1:21 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  processing alternating sibling nodes


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


****************************************************************************
This email may contain confidential material.
If you were not an intended recipient, 
please notify the sender and delete all copies.
We may monitor email to and from our network.

****************************************************************************



 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.