Pietschmann and Jarno,
Thank you for your help and suggestions.
Regards,
Sandeep Deshpande
-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com]On Behalf Of
J.Pietschmann
Sent: Friday, February 13, 2004 2:17 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Mixed Contents
Sandeep Deshpande wrote:
Hi All,
I have a problem with the elements having mixed content. The problem is as
follows.
======= XML File (x.xml ) ================
<?xml-stylesheet type="text/xsl" href="x.xsl"?>
<directory>Hi I am in a directory.
<subdirectory>Hi I am in a subdirectory.
<file>Hi I am in file1.</file>
in between two files (back to subdirectory.)
<file>Hi I am in file2.</file>
in between two files (back to subdirectory.)
<file>Hi I am in file3.</file>
out of file. back to subdirectory.</subdirectory>
out of subdirectory. back to directory.</directory>
================================
======= XSL File (x.xsl ) ================
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/TR/WD-xsl">
^^^^^^^^^^^^^^^^^^^^^^^^^^^
Fix this first, according to the hint in the other post.
Actually, the rest of the code you provided is standard
XSLT rather that WD-XSL.
.....
<xsl:template match="directory">
<br/><xsl:value-of select="text()"/><br/>
<xsl:apply-templates select="subdirectory"/>
<br/><xsl:value-of select="text()[1]"/><br/>
</xsl:template>
That's convoluten and wont do what you expect. All the
XPath expressions are relative to the context node, which
means that the first as well as the second xsl:value-of
result in the same text, specifically "Hi I am in a directory..."
(trailing whitespace replaced by ellipsis).
You have to think in terms of traversing a tree rather
than pulling text snippet from a string.
The following will be closer to your requirements:
<xsl:stylesheet version="1.0"
"xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html><head><title/</head>><body>
<xsl:apply-templates/>
</body></html>
</xsl:template>
<xsl:template match="directory">
<xsl:apply-templates/>
<br/>
</xsl:template>
<xsl:template match="subdirectory">
<font color="red">
<xsl:apply-templates/>
</font><br/>
</xsl:template>
<xsl:template match="file">
<font color="blue">
<xsl:apply-templates/>
</font><br/>
</xsl:template>
</xsl:stylesheet>
This will omit some line breaks. Adding the following template
<xsl:template match="text()">
<xsl:apply-templates/><br/>
</xsl:template>
will probably fix this for your sample code but may have unexpected
side effects in more general cases.
J.Pietschmann
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list