Re: [xsl] Elements with Mixed contents

Subject: Re: [xsl] Elements with Mixed contents
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 14 Feb 2002 14:06:28 +0000
Hi Sandeep,

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

You're not using XSLT, but rather a dialect developed by Microsoft
based on one of the very early working drafts for XSLT, which they
call "XSL". I suggest that you upgrade to XSLT before you go any
further. See the MSXML FAQ at
http://www.netcrucible.com/xslt/msxml-faq.htm for more details.

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

I can't say how "XSL" would interpret this, but in XSLT the positions
of nodes are counted from 1. The above will give you the value of the
first text node twice - once from the <xsl:value-of select="text()" />
and once from the <xsl:value-of select="text()[1]" />.

But I think that you're going about the problem in the wrong way. It
seems that what you want is, for every text node in your document, a
br element followed by the value of the text node, followed by a br
element. You should make a template that expresses that rule, as
follows:

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

Then, the templates for directory and subdirectory elements can simply
apply templates to all their children, without having to test to see
what they are, as follows:

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

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

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

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Current Thread