[xsl] Re: xsl-list Digest 9 Nov 2006 06:10:00 -0000 Issue 953

Subject: [xsl] Re: xsl-list Digest 9 Nov 2006 06:10:00 -0000 Issue 953
From: "Eric Pheatt" <eric.pheatt@xxxxxxxxx>
Date: Thu, 9 Nov 2006 10:30:34 -0800
Hi Wendell,

Thank you for responding, I guess I removed too much of my original
post and ended up being less clear.

>>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
>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>
>Can anyone point me towards a better approach using a push/functional
>approach to make simplification of wddx recordsets contextually

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

I'm using SAXON 6.5.3 via javax in a 1.4.2 java applet, (but not via the XSLTProcessorApplet interface, ) so this needs to be XSLT 1.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.)

Can you point out the specific entries in the FAQ? I'm not searching with the right words to find how to approach that recursive template call appropriately.

Here is an brief version of the wddx data:

<?xml version="1.0" encoding="UTF-8"?>
<wddxPacket version='1.0'><header></header><data><struct>
<var name='party'>
<recordset rowCount='2'
<field name='PARTY_ID'>
<field name='PARTY_ROLE_ID'>
<field name='FIRST_NAME'>
<field name='LAST_NAME'>
<field name='SUFFIX'>
<field name='BIRTH_DT'>
<var name='alias'>
<recordset rowCount='1' fieldNames='ALIAS_ID,PARTY_ID,FIRST_NAME,LAST_NAME'>
<field name='ALIAS_ID'>
<field name='PARTY_ID'>
<field name='FIRST_NAME'>
<field name='LAST_NAME'>

And the output I am hoping to get as a result is:

<?xml version="1.0" encoding="UTF-8"?>

If it is possible to do in one style sheet I would also like to make a
copy of the alias element into the party element where the party_id
identical.  But I figured that could be a separate question.

Thanks again,

Current Thread