Re: [xsl] Mixed Contents

Subject: Re: [xsl] Mixed Contents
From: "J.Pietschmann" <j3322ptm@xxxxxxxx>
Date: Thu, 12 Feb 2004 21:46:32 +0100
Sandeep Deshpande wrote:

Hi All,
I have a problem with the elements having mixed content. The problem is as

======= 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="";>
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/>

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"
   <xsl:template match="/">
   <xsl:template match="directory">
   <xsl:template match="subdirectory">
     <font color="red">
   <xsl:template match="file">
     <font color="blue">

This will omit some line breaks. Adding the following template
   <xsl:template match="text()">
will probably fix this for your sample code but may have unexpected
side effects in more general cases.


XSL-List info and archive:

Current Thread