Subject: [xsl] tricky problem filtering input and counting output From: "Trevor Nicholls" <trevor@xxxxxxxxxxxxxxxxxx> Date: Wed, 23 Feb 2011 03:38:02 +1300 |
Hi My input XML is grouped into documents and sections which can be nested to arbitrary depth. I have a transform which processes the input into one or more output HTML documents, following the rule that any "document" element, or any "section" element with attribute "@break='Y'", should direct its output to a new file. Each output file contains navigation links to the previous and next files in the output. So far so good. The mechanism to achieve this is more or less as follows (leaving a lot to the imagination): <xsl:template match="document | section[@break='Y']"> <xsl:variable name="output"> <xsl:call-template name="subfile-name" /> </xsl:variable> <xsl:result-document href="{$output}.html"> <xsl:call-template name="html-file" /> </xsl:result-document> </xsl:template> <xsl:template name="subfile-name"> <xsl:number count="document | section[@break='Y']" level="any" /> </xsl:template> <xsl:variable name="subfile-cnt" select="count(//document) + count(//section[@break='Y'])" /> <xsl:template name="navigation"> <xsl:variable name="thisnum"> <xsl:number count="document | section[@break='Y']" level="any" /> </xsl:variable> <xsl:variable name="prevnum" select="($thisnum - 1)" /> <xsl:variable name="nextnum" select="($thisnum + 1)" /> <xsl:choose> <xsl:when test="$prevnum > 0"> <xsl:call-template name="buildlink"> <xsl:with-param name="href" select="{$prevnum}.html" /> <xsl:with-param name="content" select="'Previous'" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:text>Previous</xsl:text> </xsl:otherwise> </xsl:choose> <xsl:text> | </xsl:text> <xsl:choose> <xsl:when test="$subfile-cnt > $nextnum"> <xsl:call-template name="buildlink"> <xsl:with-param name="href" select="{$nextnum}.html" /> <xsl:with-param name="content" select="'Next'" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:text>Next</xsl:text> </xsl:otherwise> </xsl:choose> </xsl:template> This works fine because the output documents form an unbroken sequence from 1 to N. Now I am required to filter the input on some condition which means certain output HTML pages are suppressed. I can do the filtering easily enough by modifying the first template in the foregoing <xsl:template match="document | section[@break='Y']"> <xsl:variable name="output"> <xsl:call-template name="subfile-name" /> </xsl:variable> <xsl:variable name="select"> <xsl:call-template name="filter-output" /> </xsl:variable> <xsl:if test="$select='Y'"> <xsl:result-document href="{$output}.html"> <xsl:call-template name="html-file" /> </xsl:result-document> </xsl:if> </xsl:template> again, leaving the content of the "filter-output" template to your imagination. I'm sure you know what's coming next; either the output file numbering needs to be fixed so the sequence is still continuous, or the navigation template needs a means of establishing what the next and previous unsuppressed file numbers actually are. I am finding either of these extraordinarily difficult. Can someone please help me see how to cut through the knot? Thanks for any assistance Cheers Trevor
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] The set datatype implemen, Dimitre Novatchev | Thread | AW: [xsl] tricky problem filtering , Szabo, Patrick \(LNG |
Re: [xsl] RE: Cheaper to prepend or, Dimitre Novatchev | Date | Re: [xsl] Cheaper to prepend or app, Michael Kay |
Month |