Hello,
I am new to XSLT and I am trying to create an XSL stylesheet
that transforms XML to HTML. I am trying to generate a navigable side
menu and the contents of the document. My problem is that text seems
to be printed twice after I use
<pre>
<xsl:value-of select="text()"/>
</pre>
in the content section of my document. The text prints once inside the
HTML tags and immediately following the HTML tags. This happens when
the current node is not a leaf node and has one or more descendants.
I am using MSXSL 4.0 to process my stylesheet. Here is a snippet of my
xml document:
<?xml version="1.0" encoding="utf-8"?>
<Info_Log>
<Application_Logs>
<ALM>SVAL.LOG could not be found
</ALM>
<DMS>
<DMSSDB.LOG>
Date & Time: Mon Jan 14 09:43:06 2008
Release 1.41A Build 032 Oracle 9
Oracle Error Messages:
----------------------
Time and Date: Mon Jan 14 09:43:58 2008
ORA-01403: no data found
rc = 1403 in func OFETCH, OFEN
SELECT DISTINCT E.FLD_ID, E.PRECISION, E.DATA_TYP_ID, E.FLD_NM,
E.DESCRIPTION, E.LG_DFORMAT, E.S_DFORMAT, E.LOGICAL_LEN, A.TABLE_NM
FROM COMP_RATE_MUP C, DATELEM E, DATTBL A, DATREC R WHERE C.FILE_ID =
7588 AND A.FILE_ID = C.FILE_ID AND E.FLD_ID = C.RATE_FLD_ID AND
E.FLD_ID = R.FLD_ID AND A.FILE_ID = R.FILE_ID AND E.REQUIRED != 'S'
ORDER BY E.DESCRIPTION ASC
Time and Date: Mon Jan 14 09:44:33 2008
ORA-01403: no data found
rc = 1403 in func OFETCH, OFEN
SELECT DISTINCT E.FLD_ID, E.PRECISION, E.DATA_TYP_ID, E.FLD_NM,
E.DESCRIPTION, E.LG_DFORMAT, E.S_DFORMAT, E.LOGICAL_LEN, A.TABLE_NM
FROM COMP_RATE_MUP C, DATELEM E, DATTBL A, DATREC R WHERE C.FILE_ID =
7588 AND A.FILE_ID = C.FILE_ID AND E.FLD_ID = C.RATE_FLD_ID AND
E.FLD_ID = R.FLD_ID AND A.FILE_ID = R.FILE_ID AND E.REQUIRED != 'S'
ORDER BY E.DESCRIPTION ASC
</DMSSDB.LOG>ERRORLOG.TXT could not be found
</DMS>
<FTP>
<EVENT.LOG>***********************************************************
IPS-Sendero FTP log started 2007.08.21 08:34:26.541
[2007.08.21 08:35:08.660 ----- IPS-Sendero FTP:ShadowLib ----- Error]
Channel 0xDBD2E8 error detail:
Interface message: Generic Success (0)
Native message: ORA-01017: invalid username/password; logon denied
(1017)
Rec/row: -1 Fld/col: -1 SQL: <N/A>
File=.\SChannelDB.cpp, Line=752
[2007.08.21 08:35:08.660 ----- IPS-Sendero FTP:FTP GUI ----- Query]
Error: Unable to connect to Database: ORA-01017: invalid username/
password; logon denied !
File=.\MainFrm.cpp, Line=274
</EVENT.LOG>
<DAOERROR.LOG>***********************************************************
IPS-Sendero Application log started 2007.08.21 08:35:06.782
Dao Layer error: Tue Aug 21 08:35:08 2007
File: .\Svdaomgr.cpp
Line number: 84
ORA-01017: invalid username/password; logon denied
Original SQL code[-1017]:
SQL string not available. See previous
Channel Ptr: 25013fd8.
Module 10003, Failed oci olog() in openConnect().
Dao Layer error: Tue Aug 21 08:35:08 2007
File: .\Svdaomgr.cpp
Line number: 84
ORA-01017: invalid username/password; logon denied
Original SQL code[-1017]:
SQL string not available. See previous
Channel Ptr: 25013fd8.
Module 10003, Failed oci olog() in openConnect().
Tue Aug 21 08:35:11 2007
</DAOERROR.LOG>
</FTP>
</Application_Logs>
</Info_Log>
Here is my stylesheet:
<?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="/">
<html>
<head>
<meta name="author" content="IPS-Sendero" />
<title>Info.Log</title>
<xsl:element name="link">
<xsl:attribute
name="href">Info.css</xsl:attribute>
<xsl:attribute
name="rel">stylesheet</xsl:attribute>
<xsl:attribute
name="type">text/css</xsl:attribute>
</xsl:element>
<xsl:element name="script">
<xsl:attribute name="src">viewerWebScripts.js</
xsl:attribute>
<xsl:attribute
name="type">text/javascript</xsl:attribute>
</xsl:element>
</head>
<body>
<div id="page_container">
<div id="header">
</div>
<div id="side_nav">
<ol>
<xsl:apply-templates mode="sidenav"/>
</ol>
</div>
<div id="content">
<xsl:element name
="h1">Info.Log</xsl:element>
<xsl:apply-templates mode="content"/>
</div>
<div id="footer">
© 2007 IPS-Sendero.
© 2007 Fiserv, Inc.
</div>
</div>
</body>
</html>
</xsl:template>
<!-- This generates the side navigation menu section -->
<xsl:template match="/Info_Log/* " mode="sidenav">
<xsl:element name="li">
<xsl:element name="a">
<xsl:attribute name="href">
#<xsl:value-of select="name()"/>
</xsl:attribute>
<xsl:choose>
<xsl:when test="contains(name(.),'_')">
<xsl:value-of
select="substring-before(name(.),'_')"/>
<xsl:text> </xsl:text>
<xsl:value-of
select="substring-after(name(.),'_')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="name(.)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
<!-- Populate the sub menu items if the current node has child
elements -->
<xsl:if test="./*">
<xsl:element name="ol">
<xsl:for-each select="./*">
<xsl:element name ="li">
<xsl:attribute
name="class">menuitem</xsl:attribute>
<xsl:element name="a">
<xsl:attribute name="href">
#<xsl:value-of
select="name(..)"/>~<xsl:value-of
select="name(.)"/>
</xsl:attribute>
<xsl:choose>
<xsl:when test="contains(name(),'_')">
<xsl:value-of select="substring-
before(name(),'_')"/>
<xsl:text> </xsl:text>
<xsl:value-of
select="substring-after(name(),'_')"/
>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="name()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
<!-- End of Anchor Tag-->
</xsl:element>
<!-- End of LI tag -->
</xsl:for-each>
</xsl:element>
<!-- End of OL tag-->
</xsl:if>
</xsl:element>
</xsl:template>
<!-- This generates the Content section -->
<xsl:template match="Info_Log/*" mode="content" >
<xsl:element name ="h2">
<xsl:element name="a">
<xsl:attribute name="id">
<xsl:value-of select="name()"/>
</xsl:attribute>
<xsl:choose>
<xsl:when test="contains(name(),'_')">
<xsl:value-of
select="substring-before(name(),'_')"/>
<xsl:text> </xsl:text>
<xsl:value-of
select="substring-after(name(),'_')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="name()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
</xsl:element>
<xsl:if test="string-length(normalize-space(text()[1])) >
0">
<pre>
<xsl:value-of select ="text()"/>
</pre>
</xsl:if>
<xsl:apply-templates mode="content"/>
</xsl:template>
<xsl:template match ="Info_Log/*/*" mode="content">
<xsl:element name ="h3">
<xsl:element name="a">
<xsl:attribute name="id">
<xsl:value-of select="name(..)"/>~<xsl:value-of
select="name()"/>
</xsl:attribute>
<xsl:choose>
<xsl:when test="contains(name(),'_')">
<xsl:value-of
select="substring-before(name(),'_')"/>
<xsl:text> </xsl:text>
<xsl:value-of
select="substring-after(name(),'_')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="name()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
</xsl:element>
<!-- If the current node has text print it in the correct format --
>
<xsl:if test="string-length(normalize-space(text()[1])) >
0">
<pre>
<xsl:value-of select ="text()"/>
</pre>
</xsl:if>
<xsl:apply-templates mode="content"/>
</xsl:template>
<xsl:template match ="Info_Log/*/*/*" mode="content"
>
<xsl:element name ="h4">
<xsl:choose>
<xsl:when test="contains(name(),'_')">
<xsl:value-of select="substring-before(name(),'_')"/>
<xsl:text> </xsl:text>
<xsl:value-of select="substring-after(name(),'_')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="name()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
<!-- If the current node has text print it in the correct format --
>
<xsl:if test="string-length(normalize-space(text()[1])) >
0">
<pre>
<xsl:value-of select ="text()"/>
</pre>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Is the error due to the way I am using the mode attribute and the
select attribute in my templates? How can I change my stylesheet to
remove the unwanted text immediately following my tags? Any help you
could provide would be greatly appreciated.
Thanks,
|
koshin.mariano@gmail.com wrote:
> <!-- This generates the Content section -->
> <xsl:template match="Info_Log/*" mode="content"
>
> <xsl:element name ="h2">
> <xsl:element name="a">
> <xsl:attribute name="id">
> <xsl:value-of select="name()"/>
> </xsl:attribute>
> <xsl:choose>
> <xsl:when test="contains(name(),'_')">
> <xsl:value-of
select="substring-before(name(),'_')"/>
> <xsl:text> </xsl:text>
> <xsl:value-of
select="substring-after(name(),'_')"/>
> </xsl:when>
> <xsl:otherwise>
> <xsl:value-of select="name()"/>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:element>
> </xsl:element>
I haven't looked at all that code in detail but this could be the
culprit, you first output text here, then
> <xsl:if test="string-length(normalize-space(text()[1]))
> 0">
> <pre>
> <xsl:value-of select ="text()"/>
> </pre>
> </xsl:if>
here you process child nodes:
> <xsl:apply-templates mode="content"/>
That way it is possible that you output the text contained in a parent
element, then later in a child element you output the same text or part
of that text again.
--
Martin Honnen --- MVP XML
|
On Mar 3, 8:57 am, Martin Honnen <mahotr...@yahoo.de> wrote:
> koshin.mari...@gmail.com wrote:
> > <!-- This generates the Content section -->
> > <xsl:template match="Info_Log/*"
mode="content" >
> > <xsl:element name ="h2">
> > <xsl:element name="a">
> > <xsl:attribute name="id">
> > <xsl:value-of select="name()"/>
> > </xsl:attribute>
> > <xsl:choose>
> > <xsl:when test="contains(name(),'_')">
> > <xsl:value-of
select="substring-before(name(),'_')"/>
> > <xsl:text> </xsl:text>
> > <xsl:value-of
select="substring-after(name(),'_')"/>
> > </xsl:when>
> > <xsl:otherwise>
> > <xsl:value-of select="name()"/>
> > </xsl:otherwise>
> > </xsl:choose>
> > </xsl:element>
> > </xsl:element>
>
> I haven't looked at all that code in detail but this could be the
> culprit, you first output text here, then
>
> > <xsl:if test="string-length(normalize-space(text()[1]))
> 0">
> > <pre>
> > <xsl:value-of select ="text()"/>
> > </pre>
> > </xsl:if>
>
> here you process child nodes:
>
> > <xsl:apply-templates mode="content"/>
>
> That way it is possible that you output the text contained in a parent
> element, then later in a child element you output the same text or part
> of that text again.
>
> --
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/
Hi Martin,
Thanks for the response. I used <xsl:if test="string-
length(normalize-space(text()[1])) > 0"> to check if the current
node has text and the text length is > 0. I initially thought of
using the text() function but I realized that the text() function
alone but I realized that the text() function includes the text of
child elements as well which is not what I wanted. I only want to
examine if the current node has text and print the text between html
<pre> tags. I'll try your suggestions and see if that works.
Thanks,
|