xsl-list
[Top] [All Lists]

Re: XSLT real time use of XML to XML Transformation (Updated Querry)

2003-06-10 15:18:54
Hi Heath (Allison?),

I'm afraid I can't debug your code since the approach you take is so far from the one I would prefer ... which is simpler and easier, but which might come across as an "advanced" technique to an XSLT newcomer.

Briefly, it is to see your problem as a grouping problem (which it is). If it were me, I'd make a key like so:

<xsl:key name="data-by-agent" match="CLIENTDATA" use="generate-id(preceding-sibling::USER[1])"/>

Then I'd do something like:

<xsl:template match="CLIENTDATA"/>
<!-- suppresses processing of CLIENTDATA nodes on regular traversal -->

<xsl:template match="USER">
  <AGENT>
    <xsl:variable name="thisagentdata"
      select="key('data-by-agent', generate-id())"/>
    <!-- the variable is bound to the three CLIENTDATA nodes belonging to
         this USER -->
    <AGENTNAME><xsl:value-of select="."/></AGENTNAME>
    <AGENTID>
      <xsl:value-of select="$thisagentdata[1]"/>
    </AGENTID>
    <AGENTAGE>
      <xsl:value-of select="$thisagentdata[2]"/>
    </AGENTAGE>
    <AGENTSTATUS>
      <xsl:value-of select="$thisagentdata[3]"/>
    </AGENTSTATUS>
  </AGENT>
</xsl:template>

An excellent guide to grouping problems may be found at www.jenitennison.com. Using keys (the <xsl:key/> declaration and the key() function) are documented in the spec and in any reasonably decent how-to book on XSLT.

I hope this helps,
Wendell

At 04:29 PM 6/10/2003, you wrote:
I've made some progress hacking away at my problem using information I found in the archives, but I'm still stuck on a few points....



======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)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



<Prev in Thread] Current Thread [Next in Thread>