Re: [xsl] Re: WDDX Recordset generic simplification

Subject: Re: [xsl] Re: WDDX Recordset generic simplification
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 08 Nov 2006 11:18:51 -0500
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@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