[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Lucas,
While as I said, you can, technically, do this with xsl:for-each, doing so here is making your code excessively complex and difficult to debug. When I broke it out into templates it became immediately clear how list-items are being generated in the wrong places (among other problems).
Basically you need a logic like what I described:
If you scrutinize this, you'll see it describes your sublist structure exactly, while mapping the source elements to the formatting objects needed to create the lists inside lists. Note that while sublist items appear, they never appear except inside list-blocks, where they are legal.
Here's an illustration of this in XSLT using templates.
(Note: untested!)
One these are in templates we see how much code duplication there is, since the same structure appears over and over at different levels. It could in fact be collapsed into something much smaller and neater.
But I think you should look at this and get it working before you move onto that, as a more advanced exercise. :->
Re: [xsl] XSL-FO list with sublist
Subject: Re: [xsl] XSL-FO list with sublist From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Fri, 14 Dec 2007 13:01:35 -0500 |
Lucas,
While as I said, you can, technically, do this with xsl:for-each, doing so here is making your code excessively complex and difficult to debug. When I broke it out into templates it became immediately clear how list-items are being generated in the wrong places (among other problems).
Basically you need a logic like what I described:
At the top, generate a list each goal becomes a list item it contains a header test (in a block) if it contains questions, it gets a list (a list-block) each question becomes a list item it contains a header text (in a block) if it contains metrics, it gets a list (a list-block) each metric becomes a list item it contains its text
If you scrutinize this, you'll see it describes your sublist structure exactly, while mapping the source elements to the formatting objects needed to create the lists inside lists. Note that while sublist items appear, they never appear except inside list-blocks, where they are legal.
Here's an illustration of this in XSLT using templates.
<xsl:template match="/"> <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> <fo:layout-master-set> ... </fo:layout-master-set>
<fo:page-sequence master-reference="simple"> <fo:flow flow-name="xsl-region-body"> <fo:block> ... </fo:block>
<xsl:call-template name="listBlock"/> <!-- dropping the list into the flow here -->
</fo:flow> </fo:page-sequence> </fo:root> </xsl:template>
<xsl:template name="listBlock"> <fo:list-block> <xsl:apply-templates select="gqmroot/goal"/> <!-- each goal gets its own list item --> </fo:list-block> </xsl:template>
<xsl:template match="goal"> <!-- each goal gets its own list item --> <fo:list-item> <fo:list-item-label> <fo:block/> </fo:list-item-label> <fo:list-item-body> <!-- inside the body, first our header text --> <fo:block> <xsl:value-of select="@titleGoal"/> </fo:block> <!-- after the header text, we may need a list for our questions --> <xsl:if test="question"> <fo:list-block> <xsl:apply-templates select="question"/> <!-- each question gets its own list item --> </fo:list-block> </xsl:if> </fo:list-item-body> </fo:list-item> </xsl:template>
<xsl:template match="question"> <!-- similarly, each question gets its own list item --> <fo:list-item> <fo:list-item-label> <fo:block/> </fo:list-item-label> <fo:list-item-body> <!-- inside the body, first our header text --> <fo:block> <xsl:value-of select="@titleQuestion"/> </fo:block> <!-- after the header text, we may need a list for our metrics --> <xsl:if test="metric"> <fo:list-block> <xsl:apply-templates select="metric"/> <!-- each metric gets its own list item --> </fo:list-block> </xsl:if> </fo:list-item-body> </fo:list-item> </xsl:template>
<xsl:template match="metric"> <!-- similarly, each metric gets its own list-item --> <fo:list-item> <fo:list-item-label> <fo:block/> </fo:list-item-label> <fo:list-item-body> <fo:block> <xsl:value-of select="@titleMetric"/> <xsl:value-of select="unparsed-text(@ChartLink)" disable-output-escaping="yes"/> </fo:block> </fo:list-item-body> </fo:list-item> </xsl:template>
(Note: untested!)
One these are in templates we see how much code duplication there is, since the same structure appears over and over at different levels. It could in fact be collapsed into something much smaller and neater.
But I think you should look at this and get it working before you move onto that, as a more advanced exercise. :->
I hope this helps, Wendell
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx 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 ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XSL-FO list with sublist, Lucas Gonçalves Gros | Thread | Re: [xsl] XSL-FO list with sublist, Lucas Gonçalves Gros |
Re: [xsl] String hashing code, James A. Robinson | Date | Re: [xsl] XSL-FO and unparsed-text(, Wendell Piez |
Month |