stupid mistake?

D

David Schwartz

So, I want to do what should be a pretty straightforward. Figure
captions in my document can have footnote or link elements as well as
straight text. I would think that the following simple template would
produce the desired outcome but, instead, the original link and
footnote markup is included.

What am I doing wrong?!?

TIA,
David

==============
XSL code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<xsl:template match="caption">

<br /><br />
</p>
</xsl:template>

</xsl:stylesheet>
==============
Original Markup:
<caption position = "2">Designer illustrates that collection panels,
which contain the fields of a form under construction in the top of
this example, can use composed &lt;footnote position='1'>A composed
view is one in which spatial relationships of the parts contribute to
the overall meaning.&lt;/footnote> views of objects.</caption>
==============
Current output example:
Figure 2. Designer illustrates that collection panels, which contain
the fields of a form under construction in the top of this example,
can use composed <footnote position='1'>A composed view is one in
which spatial relationships of the parts contribute to the overall
meaning.</footnote> views of objects.
 
J

Joe Kesselman

You're invoking apply-templates. XSLT's default template copies all
contained text, NOT all contained content; if you want that behavior you
need to explicitly add the Identity Template (see the spec or any good
XSLT tutorial).
 
P

Peter Flynn

David said:
So, I want to do what should be a pretty straightforward. Figure
captions in my document can have footnote or link elements as well as
straight text. I would think that the following simple template would
produce the desired outcome but, instead, the original link and
footnote markup is included.

What am I doing wrong?!?

TIA,
David

==============
XSL code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<xsl:template match="caption">

<p class="caption">
Figure <xsl:value-of select="@position"/>. <xsl:apply-templates/
<br /><br />
</p>
</xsl:template>

</xsl:stylesheet>
==============
Original Markup:
<caption position = "2">Designer illustrates that collection panels,
which contain the fields of a form under construction in the top of
this example, can use composed &lt;footnote position='1'>A composed

Why is this &lt; and not < (here and for the end-tag)?
view is one in which spatial relationships of the parts contribute to
the overall meaning.&lt;/footnote> views of objects.</caption>
==============
Current output example:
Figure 2. Designer illustrates that collection panels, which contain
the fields of a form under construction in the top of this example,
can use composed <footnote position='1'>A composed view is one in
which spatial relationships of the parts contribute to the overall
meaning.</footnote> views of objects.

Were you expecting the footnote element start-tag and end-tag to be
reproduced in the output automatically? That won't happen unless you
provide a template for the footnote element, even if all it does is
reproduce itself as it stands, eg

<xsl:template match="footnote">
<xsl:copy-of select="."/>
</xsl:template>

To make this work, your original must use proper elements, and not try
to fudge things with &lt;
<caption position = "2">Designer illustrates that collection panels,
which contain the fields of a form under construction in the top of
this example, can use composed<footnote position='1'>A composed
view is one in which spatial relationships of the parts contribute to
the overall meaning.</footnote> views of objects.</caption>

Note particularly that the footnote start-tag *must* begin immediately
after the word to which it is attached, *with no space*, otherwise when
it comes to be rendered in the browser, the footnote mark (number or
symbol) will be separated from the words "can use composed" bu a space,
and if that falls at the end of the line, your readers may see the
footnote mark at the start of the next line.

However, if you want the footnote to be formatted in the browser as a
real footnote, you're going to have to make some decisions about how to
do that in an environment which is essentially pageless. In a table or
figure, it's easier, because the footnote doesn't get moved to the
bottom of the page, but only to the bottom of the figure.

To do this, your footnote template just outputs the footnote mark, for
example a superscripted letter; and you postpone the processing of the
footnote text itself until after the rest of the figure and caption.

Thus if your input document says:

<?xml version="1.0"?>
<figure image="foo.png">
<caption position = "2">Designer illustrates that collection panels,
which contain the fields of a form under construction in the top
of this example, can use composed<footnote position='1'>A composed
view is one in which spatial relationships of the parts
contribute to the overall meaning.</footnote> views of
objects.</caption>
</figure>

you could use the following XSLT:

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:eek:utput method="html"/>

<xsl:template match="/">
<html>
<head>
<title></title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match="figure">
<div class="figure">
<img src="{@image}" alt="whatever"/>
<xsl:apply-templates/>
<xsl:if test="descendant::footnote">
<hr width="1in"/>
<ul>
<xsl:for-each select="descendant::footnote">
<li type="a">
<xsl:apply-templates/>
</li>
</xsl:for-each>
</ul>
</xsl:if>
</div>
</xsl:template>

<xsl:template match="caption">
<p class="caption">
<xsl:text>Figure </xsl:text>
<xsl:number format="1" count="//figure"/>
<xsl:text>. </xsl:text>
<xsl:apply-templates/>
</p>
</xsl:template>

<xsl:template match="footnote">
<sup>
<xsl:number format="a"/>
</sup>
</xsl:template>

</xsl:stylesheet>

This produces:

<html>
<head>
<title></title>
</head>
<body>
<div class="figure">
<img src="foo.png" alt="whatever">
<p class="caption">Figure 1. Designer illustrates that
collection panels, which contain the fields of a form
under construction in the top of this example, can use
composed<sup>a</sup> views of objects.</p>
<hr width="1in">
<ul>
<li type="a">A composed view is one in which spatial
relationships of the parts contribute to the overall
meaning.</li>
</ul>
</div>
</body>
</html>

General footnotes can be handled using a similar method in order to
place footnotes at the end of the chapter/section/subsection in which
they occur (as HTML has no real "pages"). For an example, see the
footnotes in the HTML version of my book _Formatting Information_ at
http://research.silmaril.ie/latex

///Peter
 
D

David Schwartz

You're invoking apply-templates. XSLT's default template copies all
contained text, NOT all contained content; if you want that behavior you
need to explicitly add the Identity Template (see the spec or any good
XSLT tutorial).

It turns out that my xml editor outputted '<' as '&lt;' for a few
footnote and link elements. Fixing that solved the problem.

I haven't been able to find decent references for 'Identify Template'.
Can you provide a pointer Joel?

Thanks,
David
 
J

Joseph Kesselman

As others pointed out, "identity", not "identify". (And as they didn't
point out, I'm Joe, not Joel -- though I've gotten used to that typo.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top