This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > Microsoft XML > February 2004 > Newline & tabs
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Pablo A. Tomé 2004-02-25, 10:30 am |
| Hi,
I have this XML document
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type='text/xsl' href='ejemplo.xsl'?>
<DescSP><Code>
this
is
a
test
</Code></DescSP>
I want to convert, with XSL, this code to HTML and I want to mantain the
tabulations before each word. Idem with newline characters.
The XSL code is the following:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<HTML>
<HEAD>
<TITLE>STORED PROCEDURE</TITLE>
</HEAD>
<BODY>
<xsl:apply-templates select="/DescSP/Code"/>
</BODY>
</HTML>
</xsl:template>
<xsl:template match="Code">
<xsl:call-template name="splitlines">
<xsl:with-param name="text" select="text()" />
</xsl:call-template>
</xsl:template>
<xsl:template name="splitlines">
<xsl:param name="text" />
<xsl:param name="enter" select="'
'"/>
<xsl:param name="tab" select="' '"/>
<xsl:choose>
<xsl:when test="contains( $text, $enter )">
<xsl:value-of select="substring-before( $text, $enter )"/><BR/>
<xsl:call-template name="splitlines">
<xsl:with-param name="text" select="substring-after( $text, $enter )" />
</xsl:call-template>
</xsl:when>
<xsl:when test="contains( $text, $tab )">
<xsl:value-of select="substring-before(
$text,$tab )"/>
<xsl:call-template name="splitlines">
<xsl:with-param name="text" select="substring-after( $text, $tab )" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
The problem I have is that always is executed the first WHEN, so,
I can mantain the Newlines or TABs, depending on what I put first, and I
want mantain both.
Any suggestion???
Thanks!
Pablo
| |
|
| Hi Pablo, have you considered <pre>, html tag?
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method='xml' indent='yes' omit-xml-declaration='yes'/>
<xsl:template match='/'>
<html><body>
<pre><xsl:apply-templates/></pre>
</body></html>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select='@* | node()'/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
<Pablo A. Tom? <ptome@ub.edu.ar>> wrote in message
news:eRBrvk6%23DHA.268@TK2MSFTNGP10.phx.gbl...
> Hi,
> I have this XML document
>
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <?xml-stylesheet type='text/xsl' href='ejemplo.xsl'?>
> <DescSP><Code>
> this
> is
> a
> test
> </Code></DescSP>
>
> I want to convert, with XSL, this code to HTML and I want to mantain the
> tabulations before each word. Idem with newline characters.
> The XSL code is the following:
>
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:fo="http://www.w3.org/1999/XSL/Format">
> <xsl:template match="/">
> <HTML>
> <HEAD>
> <TITLE>STORED PROCEDURE</TITLE>
> </HEAD>
> <BODY>
> <xsl:apply-templates select="/DescSP/Code"/>
> </BODY>
> </HTML>
> </xsl:template>
>
> <xsl:template match="Code">
> <xsl:call-template name="splitlines">
> <xsl:with-param name="text" select="text()" />
> </xsl:call-template>
> </xsl:template>
>
> <xsl:template name="splitlines">
> <xsl:param name="text" />
> <xsl:param name="enter" select="'
'"/>
> <xsl:param name="tab" select="' '"/>
>
> <xsl:choose>
> <xsl:when test="contains( $text, $enter )">
> <xsl:value-of select="substring-before( $text, $enter )"/><BR/>
> <xsl:call-template name="splitlines">
> <xsl:with-param name="text" select="substring-after( $text, $enter )"
/>
> </xsl:call-template>
> </xsl:when>
> <xsl:when test="contains( $text, $tab )">
> <xsl:value-of select="substring-before(
> $text,$tab )"/>
> <xsl:call-template name="splitlines">
> <xsl:with-param name="text" select="substring-after( $text, $tab )" />
> </xsl:call-template>
> </xsl:when>
> <xsl:otherwise>
> <xsl:value-of select="$text" />
> </xsl:otherwise>
> </xsl:choose>
> </xsl:template>
> </xsl:stylesheet>
>
> The problem I have is that always is executed the first WHEN, so,
> I can mantain the Newlines or TABs, depending on what I put first, and I
> want mantain both.
> Any suggestion???
> Thanks!
> Pablo
>
>
| |
| Pablo A. Tomé 2004-02-25, 11:30 am |
| Han,
Thanks for your answer, it works fine.
But, what´s wrong with the code I sent???
Thanks again!
Pablo
--
Atte.
Ing. Pablo A. Tomé
Servicio de Información a Alumnos
Universidad de Belgrano
"Han" <hp4444@kornet.net> wrote in message
news:u20Qcx6%23DHA.2552@TK2MSFTNGP09.phx.gbl...
> Hi Pablo, have you considered <pre>, html tag?
>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:output method='xml' indent='yes' omit-xml-declaration='yes'/>
>
> <xsl:template match='/'>
> <html><body>
> <pre><xsl:apply-templates/></pre>
> </body></html>
> </xsl:template>
>
> <xsl:template match="@* | node()">
> <xsl:copy>
> <xsl:apply-templates select='@* | node()'/>
> </xsl:copy>
> </xsl:template>
>
> </xsl:stylesheet>
>
> <Pablo A. Tom? <ptome@ub.edu.ar>> wrote in message
> news:eRBrvk6%23DHA.268@TK2MSFTNGP10.phx.gbl...
> />
/>[color=darkred]
>
>
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|