xsl-list
[Top] [All Lists]

AW: [xsl] tricky problem filtering input and counting output

2011-02-22 08:44:21
Hi, 

I hope I'm imagining this correctly.
Couldn't you filter the input before you do the counting ?!

You could dump the document and sections elements you don't need and count 
afterwards.


regards


. . . . . . . . . . . . . . . . . . . . . . . . . .
Patrick Szabo
 XSLT-Entwickler 
LexisNexis
Marxergasse 25, 1030 Wien

mailto:patrick(_dot_)szabo(_at_)lexisnexis(_dot_)at
Tel.: +43 (1) 534 52 - 1573 
Fax: +43 (1) 534 52 - 146 


-----Ursprüngliche Nachricht-----

Von: Trevor Nicholls [mailto:trevor(_at_)castingthevoid(_dot_)com] 
Gesendet: Dienstag, 22. Februar 2011 15:38
An: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Betreff: [xsl] tricky problem filtering input and counting output

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



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--