[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Elements with Mixed contents


Subject: RE: [xsl] Elements with Mixed contents
From: "Andrew Welch" <awelch@xxxxxxxxxxxxxxx>
Date: Thu, 14 Feb 2002 14:19:22 -0000

Hi,

Its always a bad idea to mix content like this... it causes headaches and I
havent seem a reasonable plus point for doing this.  Also, if you can, user
proper xsl and not microsoft's wd-xsl.

Anyway, here is the code in wd-xsl:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

<xsl:template match="/">
<html><body>
 <xsl:apply-templates/>
</body></html>
</xsl:template>

<xsl:template match="directory">
  <xsl:value-of select="text()"/><br/>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="subdirectory">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="subdirectory/text()">
  <xsl:value-of select="."/><br/>
</xsl:template>

<xsl:template match="file">
  <xsl:value-of select="."/><br/>
</xsl:template>

</xsl:stylesheet>

To use proper xsl, replace the <xsl:stylesheet> element with this one:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

cheers

andrew

===





-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Sandeep
Deshpande
Sent: Thursday, February 14, 2002 1:38 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Elements with Mixed contents


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">

<xsl:template match="/">
<html><body>
 <xsl:apply-templates/>
</body></html>
</xsl:template>

<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>

<xsl:template match="subdirectory">
<font color="red">
 <br/><xsl:value-of select="text()"/><br/>
<xsl:apply-templates select="file"/>
<br/><xsl:value-of select="text()[1]"/><br/>
 <br/><xsl:value-of select="text()[2]"/><br/>
 </font>
</xsl:template>

<xsl:template match="file">
<font color="blue">

 <br/><xsl:value-of select="."/></font><br/>
</xsl:template>
</xsl:stylesheet>
====================================

======= Expected output ================
Hi I am in a directory.
Hi I am in a subdirectory.
Hi I am in file1.
in between two files (back to subdirectory.)
Hi I am in file2.
in between two files (back to subdirectory.)
Hi I am in file3.
out of file. back to subdirectory.
out of subdirectory. back to directory.
====================================

======= ACTUAL OUTPUT ON IE5 ================

Hi I am in a directory.
Hi I am in a subdirectory.
Hi I am in file1.
Hi I am in file2.
Hi I am in file3.
in between two files (back to subdirectory.)
in between two files (back to subdirectory.)
out of subdirectory. back to directory.

====================================
My problems :-

1) I can not place the data occurring between two child elemet properly.
 For e.g. in between two files (back to subdirectory.) ).
2) I have to keep a counter in XSL, for the data patches of the parent
element occurring in between the child elements. ( For e.g.
<br/><xsl:value-of select="text()[2]"/><br/> ). In big size data it is
impossible to know how many data patches occur in between the child
elements.

If any of the gurus could get the solution of any of these problems, I would
be grateful.


Thanks & Regards
Sandeep Deshpande
Datamatics Technologies Limited
Ph: 91-022-8290829 ( Ext: 617 )
SDF IV, SEEPZ, Mumbai-400 096, INDIA.
Email: 2dsan@xxxxxxxxxxxxxxxxxxxx


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords