[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: dl/dt/dd matching
Francois Belanger wrote: > > I'm scratching my head on this one. I've been scratching my head for years on this one. It's a problem in DSSSL too. > What were trying to do is layout a suite of dt/dd within a dl as a table > with a row for each dt. Since there's no container for each dt (the > corresponding dl are siblings, not children of the dt node), how can one > start a new row for each dt and express that in XSL? XSL can't handle this at the moment, but I think it needs to. The processing model for xsl:for-each and xsl:apply-templates is: 1. Use a select pattern to create a list of nodes. 2. Instantiate a template once for each member of the list, creating a document fragment for each node. 3. Append the document fragments created by step 2. The last WD modified by this slightly by adding an optional step 1a that sorts the list. One way to solve the problem is to refine step 3. Suppose step 1 gives a list of element nodes: [A1, B1, A2, B2, A3, B3] Step 2, gives us a list of document fragments: [r(A1), r(B1), r(A2), r(B2), r(A3), r(B3)] where r(E) is the document fragment that results from processing element E. Step 3 gives us: r(A1) + r(B1) + r(A2) + r(B2) + r(A3) + r(B3) where + indicates concatenation. One solution is to allow nodes to be grouped together: [[A1, B1], [A2, B2], [A3, B3]] and then specify an operation f on the results of groups, thus getting f(r(A1) + r(B1)) + f(r(A2) + r(B2)) + f(r(A3) + r(B3)) For example, it might look like this: <xsl:template match="dl"> <table> <xsl:for-each select="dt|dd"> <xsl:group start="dt"> <tr><xsl:contents/></tr> </xsl:group> <td><xsl:apply-templates/></td> </xsl:for-each> </table> </xsl:template> xsl:group modifies the operation of xsl:for-each and xsl:apply-templates just as xsl:sort does. The start attribute is a match pattern that specifies the nodes that start a group; the content specifies what to do with the result of processing the members of the group; within xsl:group, xsl:contents refers to the result of appending the results of processing the members of the group. Another approach: <xsl:template match="dl"> <table> <xsl:apply-templates/> </table> </xsl:template> <xsl:template match="dt"> <tr> <td> <xsl:apply-templates/> </td> </tr> </xsl:template> <xsl:template match="dd"> <xsl:continue> <td> <xsl:apply-templates/> </td> </xsl:continue> </xsl:template> xsl:continue says the content gets added to the previous sibling in the result element tree. This is simpler but has some problems. James XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|