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

Re: FW: Basic XSLT ;-)

Subject: Re: FW: Basic XSLT ;-)
From: Geert Josten <Geert.Josten@xxxxxxxxxxx>
Date: Fri, 14 Jan 2005 14:11:13 +0100
xsl apply templates exclude
Hi Robert,

As David mentions, I'm afraid the combination of normalize-space and text gives only the normalized value of the _first_ text node in <foo>. I'm not sure that is the problem you are dealing with, but it could. And if it does, the code below might help.

Trouble is with XSLT 1 that all useful functions (like normalize and contains) only take the first node out of a node-set argument. So you need to get a single node with all the content you want to take into account.

You could try doing:
<xsl:template match="foo">
  <xsl:variable name="value">
    <xsl:copy-of select="text()" />
  </xsl:variable>

  <xsl:if test="contains($value, 'Value')">
    ...
  </xsl:if>
</xsl:template>

in which the text nodes should be merged into a single text node (in a fragment tree actually).

To make it a bit more complex, you could retrieve the value with apply-templates as well, which makes it possible to include/exclude specific elements in the content:

<xsl:template match="foo">
  <xsl:variable name="value">
    <xsl:apply-templates select="node()" mode="filter-value" />
  </xsl:variable>

  <xsl:if test="contains($value, 'Value')">
    ...
  </xsl:if>
</xsl:template>

<xsl:template match="*" mode="get-value">
  <xsl:if test="self::bar">
    <xsl:apply-templates select="node()" mode="get-value" />
  </xsl:if>
</xsl:template>

On the other hand, it could just be that your 'Value' is not tested with the correct CaSe. a translate($value, 'ABC..', 'abc..') might help in that case..

Hope this helps...

Cheers

Robert Soesemann wrote:

I am struggeling with a really basic XSL task.  I guess I am missin
something.
I need a template that matches the text values of all foo element whose
original value is 'Value'.
The original value should be normalized as I want to match e.g.:

<foo> Text </foo>

or

<foo>Text </foo>

or

<foo name="bar"> Text <child>...</child> </foo>

I tried without success:
------------------------

<xsl:template match="foo[normalize-space(text())='Value']">
....
</xsl:template>

Please help!! ;-)




-- Geert.Josten@xxxxxxxxxxx IT-consultant at Daidalos BV, Zoetermeer (NL)

http://www.daidalos.nl/
tel:+31-(0)79-3316961
fax:+31-(0)79-3316464

GPG: 1024D/12DEBB50

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.