This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: forward references from non-ordered input?


One solution, simple though not particularly elegant, is to output anchors
(<a name=...>) for the elements that are absent as well as those that are
present. Then your forward reference can always point to the next element,
without worrying about whether the element is actually there or not. There's
no harm in HTML having multiple anchors at the same place.

Your stylesheet then takes the form:

<a name="xyz"/>
<xsl:apply-templates select="table[@foo='xyz']">
  <xsl:with-param name="next" select="'abc'"/>
</xsl:apply-templates>

<a name="abc"/>
<xsl:apply-templates select="table[@foo='abc']">
  <xsl:with-param name="next" select="'def'"/>
</xsl:apply-templates>

...etc

<xsl:template match="table">
  <xsl:param name="next/">
    <tr>
      <td><a href="#{$next}">Next</a></td>
      ...
    </tr>
</xsl:template>

Another approach that occurs to me is to have a global variable containing a
comma-separated list of the items

<xsl:variable name="list" select="xyz,abc,def,..."/>

Instead of the hard-coded sequence of apply-templates calls you could then
do a recursive traversal of this list, at each stage taking the name of the
current element as the first item in the list and the name of the next one
as the second element, and making the recursive call strip off the first
item in the list in the usual way.

Mike Kay


> -----Original Message-----
> From: owner-xsl-list@lists.mulberrytech.com
> [mailto:owner-xsl-list@lists.mulberrytech.com]On Behalf Of
> Graham Seaman
> Sent: 13 September 2001 15:12
> To: xsl-list@lists.mulberrytech.com
> Subject: Re: [xsl] forward references from non-ordered input?
>
>
> On Thu, 13 Sep 2001, David Carlisle wrote:
>
> >
> >
> > > Below is a simplified sketch of what I have at the moment.
> >
> > It would be better to post a (small) input document and a
> small required
> > output. It's hard to guess from some non working code what the input
> > looks like and what its supposed to do.
> >
> The input is actually xhtml; the output is html. The input is
> large, with
> many includes, and the transformation I'm asking about is one of many
> on the same input, so I can't easily post a whole real example.
> Below is a simplified input and desired output; my problem is in
> generating the forward hrefs. The input files may sometimes have
> other tables with 'foo' attributes, which have to be inserted in
> a fixed order in the output, and the order of the input tables
> is arbitrary.
>
> I hope this is a little more helpful!
>
> Thanks
> Graham
>
> Sample input:
> <html>
> <head><title>Test</title></head>
> <body>
> <table foo="efg">
> 	<tr>
> 		<td>T7</td>T8</td>
> 	</tr>
> </table>
> <table foo="abc">
> 	<tr>
> 		<td>T1</td>T2</td>
> 	</tr>
> </table>
> <table foo="xyz">
> 	<tr>
> 		<td>Lots of other content, including nested tables</td>
> 	</tr>
> </table>
> <table foo="def">
> 	<tr>
> 		<td>T5</td>T6</td>
> 	</tr>
> </table>
> </body>
> </html>
>
>
> Desired output:
>
> <html>
> <head><title>Test</title></head>
> <body>
> <a href="#0">Skip to navigation</a>
> <table foo="xyz">
> 	<tr>
> 		<td>Lots of other content, including nested
> tables, now transformed in various ways</td>
> 	</tr>
> </table>
> <a name="0">DEF</a>
> <table foo="def">
> 	<tr>
> 		<td><a href="#1">Skip to EFG</a></td><td>T5</td>T6</td>
> 	</tr>
> </table>
> <a name="1">EFG</a>
> <table foo="def">
> 	<tr>
> 		<td><a href="#2">Skip to ABC</a></td><td>T7</td>T8</td>
> 	</tr>
> </table>
> <a name="2">ABC</a>
> <table foo="abc">
> 	<tr>
> 		<td>T1</td>T2</td>
> 	</tr>
> </table>
> </body>
> </html>
>
>
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]