Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] inserting structure

From: Manfred Staudinger <manfred.staudinger@--------->
To:
Date: 7/2/2005 11:51:00 PM
Thank you for your fast response!

> Oddly, your title says it all: you need to insert structure, but instead
you
> are trying to insert characters strings like "</p>" and "<p>" ...
I did this because i did not know how and wanted to show the intention.
Thanks
to your hint I wrote a solution based on xsl:element, see below.

> I'm sorry, but I don't have time this evening to show you a solution to
this
> problem.
No problem, I'm interested more in your experience and opinion about
reliable solutions and good style programming. So could you have a look and
at my solution in general and specifically about string handling and
parameter
usage?

> > Also the recursive template prevents me from adding html header
information.
I still don't know how to do this.

Best regards, Manfred


<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method = "html" />
<xsl:template match="/" name="replaceLineBreaks">
<xsl:param name="string" select="." />
<xsl:param name="switch" select="0" />
<xsl:param name="A" select="." />
<xsl:choose>
   <xsl:when test="contains($string, '&#xA;')">
      <xsl:choose>
         <xsl:when test="starts-with($string, '      ')">
            <xsl:element name="p">
               <xsl:value-of select="substring-before($A, $string)" />
	  </xsl:element>
            <xsl:call-template name="replaceLineBreaks">
               <xsl:with-param name="string"
select="substring-after($string, '&#xA;')" />
               <xsl:with-param name="switch" select="1" />
               <xsl:with-param name="A" select="$string" />
            </xsl:call-template>
         </xsl:when>
         <xsl:when test="starts-with($string, '   ') and $switch=0">
            <xsl:call-template name="replaceLineBreaks">
               <xsl:with-param name="string"
select="substring-after($string, '&#xA;')" />
               <xsl:with-param name="switch" select="1" />
               <xsl:with-param name="A" select="$string" />
            </xsl:call-template>
         </xsl:when>
         <xsl:when test="starts-with($string, '   ') and $switch=1">
            <xsl:call-template name="replaceLineBreaks">
               <xsl:with-param name="string"
select="substring-after($string, '&#xA;')" />
               <xsl:with-param name="switch" select="1" />
               <xsl:with-param name="A" select="$A" />
            </xsl:call-template>
         </xsl:when>
         <xsl:when test="starts-with($string, 'fol.')">
            <xsl:variable name = "B" >
               <xsl:value-of select="substring-before($A, $string)" />
               <xsl:text>[</xsl:text>
               <xsl:value-of select="substring-before($string, '&#xA;')" />
               <xsl:text>]</xsl:text>
               <xsl:value-of select="substring-after($string, '&#xA;')" />
            </xsl:variable>
            <xsl:call-template name="replaceLineBreaks">
               <xsl:with-param name="string"
select="substring-after($string, '&#xA;')" />
               <xsl:with-param name="switch" select="1" />
               <xsl:with-param name="A" select="$B" />
            </xsl:call-template>
         </xsl:when>
         <xsl:otherwise>
            <xsl:if test="$switch=1">
	     <xsl:element name="p">
                  <xsl:value-of select="substring-before($A, $string)" />
	     </xsl:element>
            </xsl:if>
            <div><xsl:value-of select="substring-before($string,
'&#xA;')" /></div>
            <xsl:call-template name="replaceLineBreaks">
               <xsl:with-param name="string"
select="substring-after($string, '&#xA;')" />
               <xsl:with-param name="switch" select="0" />
               <xsl:with-param name="A"
select="substring-after($string, '&#xA;')" />
            </xsl:call-template>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:when>
   <xsl:when test="$switch=1">
      <xsl:element name="p">
         <xsl:value-of select="$A" />
      </xsl:element>
   </xsl:when>
   <xsl:otherwise>
      <div><xsl:value-of select="$string" /></div>
   </xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent