Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Line breaks in XSL files 1

Status
Not open for further replies.

bazil2

Technical User
Feb 15, 2010
148
DE
(Elementary user)

I have XSL files that use XML mark up language that I need to edit.

I would like to insert line breaks in to some text that needs to be displayed.

I have tried <BR /> to no avail.

Does anyone have any ideas?

Best regards
 
There are multitude ways of reading of the question. It is absolutely unclear. Can you pose the question again? Line break, where to appear? in the xsl document? in the resultant document of the transformation? ...
 
Many thanks!

Well here's an abridged version of my document, the goal is to get a line break after the ... first line.

<xsl:template name="iGetOptOutInstructions" match="/">
This is the text that should appear on the first line.
And this text should appear on the second line
</xsl:template>

Below is the header of my document:

<?xml version="1.0" encoding="UTF-8"?>
<!-- returns footer for email notification which explains where the notification originated and how to opt out -->

<xsl:stylesheet xmlns:xsl=" version="1.0" xml:space="preserve">

<xsl:eek:utput method="html" />
 
[1] From the outline shown, I would say, take out the match attribute in the named template. And a <br /> should serve the bill? And since, it is not clear the surrounding where the name templated is called, I put a further div tag to wrap it. You can further style it as needed.
[tt]
<xsl:template name="iGetOptOutInstructions">
<div>
This is the text that should appear on the first line.
<br />
And this text should appear on the second line
</div>
</xsl:template>
[/tt]
[1.1] The whitespaces would be collapsed in the html page. Hence, I think it should do no matter how much space and line break appear in xsl document?

[2] Often, wrapping it with a <pre> tag may help at the first instance to get the general picture before elaborate it with br or div etc.
 
Thank you very much for your help! I have implemented the changes however the resulting email unfortunately didn't recognise the breaks. I will paste the entire document below; the changes I have made are near the bottom.

Many thanks:

-------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<!-- returns footer for email notification which explains where the notification originated and how to opt out -->

<xsl:stylesheet xmlns:xsl=" version="1.0" xml:space="preserve">

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

<xsl:template name="GetFooter" match="/">
<xsl:call-template name="iGetFooter">
<xsl:with-param name="strOptOutInstructions"><xsl:call-template name="iGetOptOutInstructions" /></xsl:with-param>
</xsl:call-template>
</xsl:template>


<xsl:template name="GetSubscriberFooter" match="/">
<xsl:call-template name="iGetFooter">
<xsl:with-param name="strOptOutInstructions"><xsl:call-template name="iGetSubscriberOptOutInstructions" /></xsl:with-param>
</xsl:call-template>
</xsl:template>

<xsl:template name="GetTokenFooter" match="/">
<xsl:call-template name="iGetFooter">
<xsl:with-param name="strOptOutInstructions"></xsl:with-param>
</xsl:call-template>
</xsl:template>

<xsl:template name="GetVendorNotificationFooter" match="/">
<xsl:call-template name="iGetFooter">
<xsl:with-param name="strOptOutInstructions"><BR />Wenn Sie keine weiteren Benachrichtigungs-E-Mails dieser Art erhalten möchten, setzen Sie sich bitte mit dem Drucker in Verbindung, und lassen Sie sich aus der Verteilerliste austragen.</xsl:with-param>
</xsl:call-template>
</xsl:template>


<xsl:template name="iGetFooter" match="/">

<xsl:param name="strOptOutInstructions" />

<TABLE WIDTH="50%">
<TR>
<TD ALIGN="LEFT" VALIGN="BOTTOM">
<SPAN CLASS="baseSansBoldBlue">
Info zu dieser E-Mail
</SPAN>

<HR WIDTH="100%" />
</TD>
</TR>

<TR>
<TD ALIGN="LEFT" VALIGN="BOTTOM">
<SPAN CLASS="baseSans">
Diese E-Mail wurde automatisch von InSite generiert: <A HREF="{ //Notification/ServerURL }"> <xsl:value-of select="//Notification/ServerURL" /></A>
<BR />
<xsl:value-of select="$strOptOutInstructions" />
</SPAN>
</TD>
</TR>
</TABLE>
</xsl:template>


<xsl:template name="iGetOptOutInstructions" match="/">
Wenn Sie keine weiteren E-Mail-Benachrichtigungen dieser Art erhalten möchten, melden Sie sich bitte bei InSite an, bearbeiten Sie Ihr Benutzerprofil, und wählen Sie die Option 'Alle E-Mail-Benachrichtigungen deaktivieren' aus.
</xsl:template>


<xsl:template name="iGetSubscriberOptOutInstructions">
<div>
Wenn Sie keine weiteren E-Mail-Benachrichtigungen dieser Art erhalten möchten, melden Sie sich bitte bei InSite an, bearbeiten Sie Ihr Benutzerprofil, und ändern Sie die abonnierten E-Mail-Ereignisse entsprechend.
<br />
My Comapny
<br />
My Road
<br />
My ZIP Code
<br />
My country
</div>
</xsl:template>

</xsl:stylesheet>
 
[3] As I mentioned, named template may have match attribute. But, it would subject to the same competition/priority rule when there are conflicts of match. In your xsl document, there are "ton" of templates (named) that match document root (/). That mean, more or less, the last would win out.

[4] This is an attempt to rectify all the conflicts, see if it does something positive in your cause.
[tt]
<?xml version="1.0" encoding="UTF-8"?>
<!-- returns footer for email notification which explains where the notification originated and how to opt out -->

<xsl:stylesheet xmlns:xsl="[ignore][/ignore]" version="1.0" xml:space="preserve">

<xsl:eek:utput method="html" />
[blue]
<xsl:template match="/">
<html><body>
<!-- call other named templates as needed -->
<xsl:call-template name="GetFooter" />
<!-- call other named templated as needed -->
</body></html>
</xsl:template>
[/blue]
<xsl:template name="GetFooter[highlight]">[/highlight]
<xsl:call-template name="iGetFooter">
<xsl:with-param name="strOptOutInstructions"><xsl:call-template name="iGetOptOutInstructions" /></xsl:with-param>
</xsl:call-template>
</xsl:template>

<xsl:template name="GetSubscriberFooter[highlight]">[/highlight]
<xsl:call-template name="iGetFooter">
<xsl:with-param name="strOptOutInstructions"><xsl:call-template name="iGetSubscriberOptOutInstructions" /></xsl:with-param>
</xsl:call-template>
</xsl:template>

<xsl:template name="GetTokenFooter[highlight]">[/highlight]
<xsl:call-template name="iGetFooter">
<xsl:with-param name="strOptOutInstructions"></xsl:with-param>
</xsl:call-template>
</xsl:template>

<xsl:template name="GetVendorNotificationFooter[highlight]">[/highlight]
<xsl:call-template name="iGetFooter">
<xsl:with-param name="strOptOutInstructions"><BR />Wenn Sie keine weiteren Benachrichtigungs-E-Mails dieser Art erhalten möchten, setzen Sie sich bitte mit dem Drucker in Verbindung, und lassen Sie sich aus der Verteilerliste austragen.</xsl:with-param>
</xsl:call-template>
</xsl:template>

<xsl:template name="iGetFooter[highlight]">[/highlight]

<xsl:param name="strOptOutInstructions" />

<TABLE WIDTH="50%">
<TR>
<TD ALIGN="LEFT" VALIGN="BOTTOM">
<SPAN CLASS="baseSansBoldBlue">
Info zu dieser E-Mail
</SPAN>

<HR WIDTH="100%" />
</TD>
</TR>

<TR>
<TD ALIGN="LEFT" VALIGN="BOTTOM">
<SPAN CLASS="baseSans">
Diese E-Mail wurde automatisch von InSite generiert: <A HREF="{ //Notification/ServerURL }"> <xsl:value-of select="//Notification/ServerURL" /></A>
<BR />
<xsl:value-of select="$strOptOutInstructions" />
</SPAN>
</TD>
</TR>
</TABLE>
</xsl:template>


<xsl:template name="iGetOptOutInstructions[highlight]">[/highlight]
Wenn Sie keine weiteren E-Mail-Benachrichtigungen dieser Art erhalten möchten, melden Sie sich bitte bei InSite an, bearbeiten Sie Ihr Benutzerprofil, und wählen Sie die Option 'Alle E-Mail-Benachrichtigungen deaktivieren' aus.
</xsl:template>

<xsl:template name="iGetSubscriberOptOutInstructions">
<div>
Wenn Sie keine weiteren E-Mail-Benachrichtigungen dieser Art erhalten möchten, melden Sie sich bitte bei InSite an, bearbeiten Sie Ihr Benutzerprofil, und ändern Sie die abonnierten E-Mail-Ereignisse entsprechend.
<br />
My Comapny
<br />
My Road
<br />
My ZIP Code
<br />
My country
</div>
</xsl:template>

</xsl:stylesheet>
[/tt]
 
[4.1] Upon reading some of your named template, you've implemented br etc in iGetSubscriberOptOutInstructions rather than, perhaps your original, iGetOptOutInstructions. Hence, you've to change also this line.
[tt]
<xsl:template name="GetFooter">
<xsl:call-template name="iGetFooter">
<xsl:with-param name="strOptOutInstructions"><xsl:call-template name="iGet[red]Subsriber[/red]OptOutInstructions" /></xsl:with-param>
</xsl:call-template>
</xsl:template>
[/tt]
 
[4.1.1] A typo there! Here's the retake.
[tt]
<xsl:template name="GetFooter">
<xsl:call-template name="iGetFooter">
<xsl:with-param name="strOptOutInstructions"><xsl:call-template name="iGet[red]Subscriber[/red]OptOutInstructions" /></xsl:with-param>
</xsl:call-template>
</xsl:template>
[/tt]
 
[5] This is a clean up version that I think illustrate the working. I have to eliminate quite a bit of unused lines to make the logic clearer. But the main thing of the clean up is to rectify some chaining of template call resulting in the lost of tagging proper. (I won't highlight the modifications, as it is that numerous.) I keep a parameter passing so that it stands ready to be extended with different value to be passed, rather than unidimensionally "iGetSubscriberOptOutInstructions".
[tt]
<?xml version="1.0" encoding="UTF-8"?>
<!-- returns footer for email notification which explains where the notification originated and how to opt out -->
<xsl:stylesheet xmlns:xsl="[ignore][/ignore]" version="1.0" xml:space="preserve">
<xsl:eek:utput method="html" />
<xsl:template match="/">
<html><body>
<!-- call other named templates as needed -->
<xsl:call-template name="GetFooter" />
<!-- call other named templated as needed -->
</body></html>
</xsl:template>

<xsl:template name="GetFooter">
<xsl:call-template name="iGetFooter">
<xsl:with-param name="strOptOutInstructions">iGetSubscriberOptOutInstructions</xsl:with-param>
</xsl:call-template>
</xsl:template>

<xsl:template name="iGetFooter">
<xsl:param name="strOptOutInstructions" />
<TABLE WIDTH="50%">
<TR>
<TD ALIGN="LEFT" VALIGN="BOTTOM">
<SPAN CLASS="baseSansBoldBlue">
Info zu dieser E-Mail
</SPAN>
<HR WIDTH="100%" />
</TD>
</TR>
<TR>
<TD ALIGN="LEFT" VALIGN="BOTTOM">
<SPAN CLASS="baseSans">
Diese E-Mail wurde automatisch von InSite generiert: <A HREF="{ //Notification/ServerURL }"> <xsl:value-of select="//Notification/ServerURL" /></A>
<BR />
<xsl:if test="$strOptOutInstructions='iGetSubscriberOptOutInstructions'">
<xsl:call-template name="iGetSubscriberOptOutInstructions" />
</xsl:if>
</SPAN>
</TD>
</TR>
</TABLE>
</xsl:template>

<xsl:template name="iGetSubscriberOptOutInstructions">
<div>
Wenn Sie keine weiteren E-Mail-Benachrichtigungen dieser Art erhalten möchten, melden Sie sich bitte bei InSite an, bearbeiten Sie Ihr Benutzerprofil, und ändern Sie die abonnierten E-Mail-Ereignisse entsprechend.
<br />
My Comapny
<br />
My Road
<br />
My ZIP Code
<br />
My country
</div>
</xsl:template>

</xsl:stylesheet>
[/tt]
[5.1] This can serve as a base so that you can see the result expected and that you can elaborate further.
 
Thank you so much for all your help; I'm trying this out!

Best regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top