xsl-list
[Top] [All Lists]

Re: XSL-FO / XSLT Transformations & Line Breaks in XML

2005-05-04 06:03:06
Craig,

The problem you're seeing is caused by the actions taken (more properly, by the actions *not* taken) in your .../header template.

In particular, the code fragment:
<fo:block
space-before="30"
space-after="30">
<xsl:value-of select="para"/>
</fo:block>
tells the XSLT processor to extract the string value of the para element contained in the header element. That extracts *all* of the text in the paragraph and completely ignores the linebreakhere element because it has no string value.

In other words, all of the text in the paragraph is consumed immediately. I doubt that the linebreakhere element gets processed at all, because it's embedded in the para element, which shields the linebreakhere element from being processed by the template you provided for it.

What you should try is:
<fo:block
space-before="30"
space-after="30">
<xsl:apply-templates/>
</fo:block>
but define another template to handle the para element. A very rough approximation of the XSLT might look something like this:

<xsl:template match="publications/header">

<fo:block
space-before="30"
space-after="30">
<xsl:value-of select="heading"/>
</fo:block>

<fo:block
space-before="30"
space-after="30">
<xsl:apply-templates/>
</fo:block>

</xsl:template>

<xsl:template match="publications/header/para">

<fo:block
space-before="30"
space-after="30">
<xsl:apply-templates/>
</fo:block>

</xsl:template>

<xsl:template match="linebreakhere">

<fo:block/>

</xsl:template>

Try this out and see how you fare.

Hope this helps,
   Jim

P.S., I'll obviously blush as soon as somebody tells me what foolish error *I*'ve made here :-)


At 5/4/2005 06:18 AM, craig webber wrote:
For arbitrary breaks, the XSLT processor needs to be able to recognize
something, so you need an element in the middle of the text, thus:

<para1>Banana Strawberry<break/>Grape Cherry</para1>

Then you can do:

<xsl:template match="para1">
  <p><xsl:apply-templates/></p>
</xsl:match>

<xsl:template match="break">
  <br/>
</xsl:match>


*** ***

This is working fine in my XSLT transfrom. But not in my XSL-FO transfrom (both use the same XML file).

I've used the following code in my XSL-FO file:

<xsl:template match="publications/header">

<fo:block
space-before="30"
space-after="30">
<xsl:value-of select="heading"/>
</fo:block>

<fo:block
space-before="30"
space-after="30">
<xsl:value-of select="para"/>
</fo:block>

</xsl:template>

<xsl:template match="publications/header/para/linebreakhere">

<fo:block
space-before="30"
space-after="30">
<xsl:value-of select="."/>
</fo:block>

</xsl:template>

And the line break appears in my XML file as follows:

<publications>
<header>

<heading>
Consultations Database
</heading>

<para>
The Department of Trade and Industry values the views of business, consumer groups and the public. We know that we will get it right delivering policy if we have consulted effectively.

<linebreakhere/>

The DTI seeks views on a range of proposals and existing policies, both through formal written consultations and through informal contact and discussion. We use a variety of consultation methods to ensure participation from a diversity of individuals and organisations/business.
</para>

</header>
</publications>

Any help would be great.

Thanks,

Craig.

_________________________________________________________________
Get news headlines and download FREE stuff - visit MSN South Africa! http://www.msn.co.za/


--~------------------------------------------------------------------
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>
--~--


========================================================================
Jim Melton --- Editor of ISO/IEC 9075-* (SQL)     Phone: +1.801.942.0144
  Co-Chair, W3C XML Query WG; F&O (etc.) editor    Fax : +1.801.942.3345
Oracle Corporation        Oracle Email: jim dot melton at oracle dot com
1930 Viscounti Drive      Standards email: jim dot melton at acm dot org
Sandy, UT 84093-1063 USA          Personal email: jim at melton dot name
========================================================================
=  Facts are facts.   But any opinions expressed are the opinions      =
=  only of myself and may or may not reflect the opinions of anybody   =
=  else with whom I may or may not have discussed the issues at hand.  =
========================================================================


--~------------------------------------------------------------------
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>
--~--