|
Subject: Re: [xsl] Response to Wolfgang Laun, Michele R Combs and G Ken Holman re Question on search and replace in XSL From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Mon, 09 Apr 2012 14:57:23 -0400 |
The input for the XML can be any number of triads of information. So for example, the input could be
aaa;bbb;ccc
The input could also be
aaa;bbb;ccc;ddd;eee;fff
Every three items needs to be formatted into a set of 3 columns.
So the first example needs to look like this:
<tr><td valign="top" width="180"></td><td valign="top" width="180">aaa</td><td valign="top" width="180">bbb</td><td valign="top" width="180">ccc</td></tr>
The second example needs to look like this:
<tr><td valign="top" width="180"></td><td valign="top" width="180">aaa</td><td valign="top" width="180">bbb</td><td valign="top" width="180">ccc</td></tr>
<tr><td valign="top" width="180"></td><td valign="top" width="180">ddd</td><td valign="top" width="180">eee</td><td valign="top" width="180">fff</td></tr>
There can be any number of triads of this type, one, two fifteen, I can't predict. To complicate things further, I cannot rely on there always being three pieces of information in each triad. So, I might have
aaa;;ccc
which needs to look like this:
<tr><td valign="top" width="180"></td><td valign="top" width="180">aaa</td><td valign="top" width="180"></td><td valign="top" width="180">ccc</td></tr>
As I said, based on your input, I've gotten closer. Here's what I have so far:
<tr> <td valign="top" width="180"></td> <xsl:apply-templates select="APName" /> </tr>
t:\ftemp>type melanie1.xml <?xml version="1.0" encoding="UTF-8"?> <tests> <APName>aaa;bbb;ccc</APName> <APName>aaa;bbb;ccc;ddd;eee;fff</APName> <APName>aaa;;ccc</APName> </tests> t:\ftemp>call xslt2 melanie1.xml melanie.xsl <?xml version="1.0" encoding="UTF-8"?>
<tr> <td valign="top" width="180"/> <td>aaa</td> <td>bbb</td> <td>ccc</td> </tr>
<tr> <td valign="top" width="180"/> <td>aaa</td> <td>bbb</td> <td>ccc</td> </tr> <tr> <td valign="top" width="180"/> <td>ddd</td> <td>eee</td> <td>fff</td> </tr>
<tr> <td valign="top" width="180"/> <td>aaa</td> <td/> <td>ccc</td> </tr>
t:\ftemp>type melanie.xsl <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="APName"> Input value: "<xsl:value-of select="."/>"
Processed output:
<!--create groups of three using the tokenized input-->
<xsl:for-each-group select="tokenize(.,';')"
group-by="( position() - 1 ) idiv 3">
<!--each group produces a row-->
<tr>
<td valign="top" width="180"></td>
<!--the members of the group make up the remaining columns-->
<xsl:for-each select="current-group()">
<td>
<xsl:value-of select="."/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each-group></xsl:stylesheet> t:\ftemp>echo Done! Done!
-- Public XSLT, XSL-FO, UBL and code list classes in Europe -- May 2012 Contact us for world-wide XML consulting and instructor-led training Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Google+ profile: https://plus.google.com/116832879756988317389/about Legal business disclaimers: http://www.CraneSoftwrights.com/legal
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] Response to Wolfgang Laun, Mi, Peterson, Melanie S. | Thread | [xsl] Haskell programmer's rant abo, Andrew Welch |
| [xsl] Response to Wolfgang Laun, Mi, Peterson, Melanie S. | Date | [xsl] Haskell programmer's rant abo, Andrew Welch |
| Month |