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

Re: Mixed Contents

Subject: Re: Mixed Contents
From: "J.Pietschmann" <j3322ptm@xxxxxxxx>
Date: Thu, 12 Feb 2004 21:46:32 +0100
sandeep deshpande
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


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.