xsl-list
[Top] [All Lists]

Re: How do I "merge" nodes based on a common key?

2004-03-26 16:50:35
Not quite - works well, sort of. problem is, I have lots of httpload, http_load, and fetch_curl nodes in my data and need to line them up ("three" per line). when I use your code below, they all showed up on one VERY long line. Also, there is no attempt made to correlate matching httpload, http_load, and fetch-curl nodes (based on their title attribute). THANKS - Yossie

On Mar 26, 2004, at 3:41 PM, Pieter Reint Siegers Kort wrote:

Hi Jopseph,

Take a look at the following xsl, which does not use a key but uses three different templates, and processes those three different templates within one row for your table. The key to this is using <xsl:apply-templates>. The
XSL is:

<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:output method="html" encoding="UTF-8" indent="yes" />

<xsl:template match="/run">
        <html>
        <head>
        <title>Title</title>
        </head>
        <body>
        <table border="1" cellpadding="6">
        <tr>
        <th>Title</th>
        <th>Cache</th>
        <th>Gzip</th>
        <th>Fetches</th>
        <th>Parallel</th>
        <th>Mbytes/Sec</th>
        </tr>
        <tr>
        <xsl:apply-templates select="http_load" />
        <xsl:apply-templates select="httpload" />
        <xsl:apply-templates select="fetch-curl" />
        </tr>
        </table>
        </body>
        </html>
</xsl:template>

<xsl:template match="http_load" >
        <td><xsl:value-of select="@title"/></td>
        <td><xsl:value-of select="fetches/text()"/></td>
        <td><xsl:value-of select="max_parallel/text()"/></td>
        <td><xsl:value-of select="mbytes_sec/text()"/></td>
</xsl:template>

<xsl:template match="httpload" >
        <td><xsl:value-of select="@cache"/></td>
        <td><xsl:value-of select="@gzip"/></td>
</xsl:template>

<xsl:template match="fetch-curl" >
</xsl:template>

</xsl:stylesheet>

This XSL outputs the following when using your XML:

<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Title</title>
</head>
<body>
<table border="1" cellpadding="6">
<tr>
<th>Title</th>
<th>Cache</th>
<th>Gzip</th>
<th>Fetches</th>
<th>Parallel</th>
<th>Mbytes/Sec</th>
</tr>
<tr>
<td>X</td>
<td>94851</td>
<td>50</td>
<td>0.617733</td>
<td>false</td>
<td>true</td>
</tr>
</table>
</body>
</html>

Note that you did not specify data to extract from the node-set 'fetch-curl' so that's why the template is an empty one. You can now add any element or
attribute as you like.

Hope this helps you in the right direction :-)

<prs/>
http://www.pietsieg.com
http://www.pietsieg.com/dotnetnuke


--+------------------------------------------------------------------
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(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--

Yossie Silverman - ENTP                   "Leave the bearded one for me"
I'NET: yossie(_at_)blacksteel(_dot_)com            - Flesh Gordon
HTTP: http://www.blacksteel.com/~yossie/  B3 f- t dc g++ k++ s++ p m e+