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

Re: looking for best way to group elements

Subject: Re: looking for best way to group elements
From: Bill French <bfh@xxxxxxxxxxxxx>
Date: Fri, 08 Sep 2006 12:55:39 -0700
node span
Hi again,

Looks like I've answered my own question.

Here's the template I wrote:

<xsl:template match="rm:group[@name = 'Languages']/rm:field[@name = 'ppl_language']" priority="3">
<xsl:variable name="pos" select="position()"></xsl:variable>
<div class="group">
<span class="meta-name">Language</span>
<span class="meta-value"><xsl:copy-of select="./node()"/></span>
<span><xsl:value-of select="../rm:field[$pos + 1]/@displayName"/></span>
<span><xsl:copy-of select="../rm:field[$pos + 1]/node()"/></span>
<span><xsl:value-of select="../rm:field[$pos + 2]/@displayName"/></span>
<span><xsl:copy-of select="../rm:field[$pos + 2]/node()"/></span>
<span><xsl:value-of select="../rm:field[$pos + 3]/@displayName"/></span>
<span><xsl:copy-of select="../rm:field[$pos + 3]/node()"/></span>
</div>
</xsl:template>


If anyone can think of a more elegant solution, I'd still love to see it.

Regards,

--Bill

Bill French wrote:
Hi,

I'm struggling to transform XML that looks like this:

<group name="Languages" displayName="Languages" order="4">
<field name="ppl_language" displayName="Language"> Spanish </field>
<field name="ppl_language" displayName="Language"> Portuguese </field>
<field name="ppl_language_native" displayName="Native?"> Yes </field>
<field name="ppl_language_native" displayName="Native?"> No </field>
<field name="ppl_language_speak" displayName="Spoken"> Fluent </field>
<field name="ppl_language_speak" displayName="Spoken"> Functional </field>
<field name="ppl_language_write" displayName="Written"> Fluent </field>
<field name="ppl_language_write" displayName="Written"> Survival </field>
</group>


What I need is output that looks like this:

Language: Spanish
Native?: Yes
Spoken: Fluent
Written: Fluent

Language: Portuguese
Native?: No
Spoken: Functional
Written: Survival

That is, the source document contains <field/> elements that are returned grouped by their @name attribute values. The <field/> elements are always returned in the order stated above, ppl_language, ppl_language_native, ppl_language_speak, and ppl_language_write. There can be an arbitrary number of language entries in the list, but it is guaranteed that for every entry, all four <field/> elements will exist.

I am having trouble devising a strategy/writing a match pattern to group the elements correctly. Can anyone make a suggestion? Obviously, the problem is that there is only one <group/> element that is the parent for all <field/> elements, no matter how many <field/> elements there are. I'm using XSLT/XPath 2.0.

Best regards,

--Bill

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.