xsl-list
[Top] [All Lists]

Re: FW: Basic XSLT ;-)

2005-01-14 06:11:13
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!! ;-)


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--
Geert(_dot_)Josten(_at_)Daidalos(_dot_)nl
IT-consultant at Daidalos BV, Zoetermeer (NL)

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

GPG: 1024D/12DEBB50

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>