[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: inserting structure

Subject: RE: inserting structure
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sun, 3 Jul 2005 15:31:42 +0100
switch structure in xslt
> 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.

This is now looking reasonably sensible, though I can't follow the logic in
detail (it would be easier to understand if your variable names were more
meaningful than A and B).

Note that you can usually rewrite

<xsl:element name="p">
...
</xsl:element>

as

<p>
...
</p>

(there's a minor difference in the handling of namespaces).

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

I would write this as

<xsl:template match="/">
  <html><head>...</head>
  <body>
    <xsl:call-template name="replaceLineBreaks">
      <xsl:with-param name="string" select="string(doc)"/>
    </xsl:call-template>
  </body>
  </html>
</xsl:template>

<xsl:template name="replaceLineBreaks">
  ...
</xsl:template>

Michael Kay
http://www.saxonica.com/


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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.