ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> xsl-list
xsl-list
Re: [xsl] Re: WDDX Recordset generic simplification
by Wendell Piez other posts by this author
Nov 8 2006 8:21AM messages near this date
[xsl] Re: WDDX Recordset generic simplification | [xsl] Cals Table
& XSLT Dear Eric,

At 08:27 PM 11/7/2006, you wrote:

> >I have an excerpt of a wddx data being generated from query data in
> >ColdFusion 5 and I need to simplify the structure with an intermediate
> >xsl transform so that I can consume the simplified form in a mail merge
> 
> [snipped]
> 
> I realize the following code does not work but it is the
> pull/procedural approach I keep getting stuck heading towards:
> 
> <xsl:template match="var/recordset">
>          <xsl:variable name="rowCount" select="@rowCount"/>
>          <xsl:variable name="fieldNames" select="@fieldNames"/>
>          <xsl:for-each from="1" to="$rowCount" index="row">
>                  <xsl:element name="{../@name}">
>                          <xsl:for-each list="$fieldNames" index="col">
>                                  <xsl:element name="{$fieldNames[$col]}">
>                                          <xsl:value-of 
>  select="field[@name=$col]::child[position()=$row]"/>
>                                  <xsl:element>
>                          </xsl:for-each>
>                  </xsl:element>
>          </xsl:for-each>
> </xsl:template>
> 
> Can anyone point me towards a better approach using a push/functional
> approach to make simplification of wddx recordsets contextually
> generic?

First, a simple question: are you using XSLT 2.0?

The reason I ask is that in XSLT 1.0 you can't generate nodes in the 
result by iterating over a set of numbers, which is effectively what 
you are trying to do here. xsl:for-each doesn't accept "from" and 
"to" attributes, as its purpose is to select a set of *nodes* (from 
the source tree) and operate with each of them in turn as the current 
node. (In this, it's really just a shortcut to allow you to do this 
locally without calling a new template rule, which is what you'd 
ordinarily do.)

Due to its expanded data model, however, in XSLT 2.0 you can say

<xsl:for-each select="1 to $rowCount"> ...</xsl:for-each>

and (due to the semantics of the 'to' operator) operate over a 
sequence of numbers (integers, actually), 1 to whatever $rowCount is.

Hence, in XSLT 2.0 the correction would be a simple syntax tweak.

In XSLT 1.0, however, you would have to execute this recursively, 
calling a template from itself and counting up to or down from 
$rowCount with a parameter as you did so, to effect a stop condition. 
(There are examples from that in the XSL FAQ.)

Cheers,
Wendell



======================================================================
Wendell Piez                            mailto:wapiez@[...].com
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
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe@[...].com> 
--~--
Thread:
Eric Pheatt
Eric Pheatt
Wendell Piez

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved