Subject: Re: [xsl] Aligning Parallel Columns From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Sat, 15 Jan 2011 10:47:13 -0500 |
Thanks for the hint. My current solution depends on being able to sort the names, which isn't entirely satisfying ($a and $b contain the two divs to be aligned):
<table> <xsl:for-each-group group-by="@name" select="$a/p, $b/p"> <xsl:sort select="@name"/>
<xsl:variable name="name" select="@name"/>
<tr> <td> <xsl:value-of select="$name"/> </td> <td> <xsl:if test="$a/p[@name = $name]"> <xsl:apply-templates select="$a/p[@name = $name]"/> </xsl:if> </td> <td> <xsl:if test="$b/p[@name = $name]"> <xsl:apply-templates select="$b/p[@name = $name]"/> </xsl:if> </td> </tr> </xsl:for-each-group> </table>
t:\ftemp>type jeroen1.xml <div id="ch1"> <p name="a1">Eerste Alinea.</p> <p name="a1.1">Zomaar ertussen.</p> <p name="a2">Tweede Alinea.</p> <p name="a3">Derde Alinea.</p> </div>
t:\ftemp>type jeroen2.xml <div id="ch2"> <p name="a1">First Paragraph.</p> <p name="a2">Second Paragraph.</p> <p name="a2.1">Something added here.</p> <p name="a3">Third Paragraph.</p> </div>
t:\ftemp>xslt2 jeroen.xsl jeroen.xsl <?xml version="1.0" encoding="UTF-8"?> <table><!--a1--><tr> <td>Eerste Alinea.</td> <td>First Paragraph.</td> </tr> <!--a1.1--><tr> <td>Zomaar ertussen.</td> <td/> </tr> <!--a2--><tr> <td>Tweede Alinea.</td> <td>Second Paragraph.</td> </tr> <!--a2.1--><tr> <td/> <td>Something added here.</td> </tr> <!--a3--><tr> <td>Derde Alinea.</td> <td>Third Paragraph.</td> </tr> </table> t:\ftemp>type jeroen.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="/"> <xsl:variable name="parent1" select="document('jeroen1.xml')/*"/> <xsl:variable name="parent2" select="document('jeroen2.xml')/*"/> <table> <xsl:for-each-group select="$parent1/p,$parent2/p" group-by="@name"> <xsl:sort select="@name"/> <xsl:comment select="current-grouping-key()"/> <tr> <td> <xsl:apply-templates select="current-group()[.. is $parent1]"/> </td> <td> <xsl:apply-templates select="current-group()[.. is $parent2]"/> </td> </tr> </xsl:for-each-group> </table> </xsl:template>
</xsl:stylesheet> t:\ftemp>
-- Contact us for world-wide XML consulting & instructor-led training Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Aligning Parallel Columns, Jeroen Hellingman | Thread | Re: [xsl] Aligning Parallel Columns, Michael Kay |
Re: [xsl] Aligning Parallel Columns, Jeroen Hellingman | Date | Re: [xsl] Aligning Parallel Columns, Michael Kay |
Month |