Re: [xsl] RE: Next node name

Subject: Re: [xsl] RE: Next node name
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 3 Apr 2002 18:44:55 +0100
Hi Francisco,

> What I do is: when the node has no name, it means we are in a text
> node, so there's nothing to do with it unless it's between two nodes
> with name (the "ut" nodes), then is when I have to replace. For the
> nodes with name (the "ut" nodes) I just do nothing so they are
> removed.
>
> What I need to know is how to reference the next and previous node
> names to check if they are "ut" nodes.

The easiest way to check that you are on a text node is with:

  self::text()

Or you could apply templates to the child nodes of the seg element in
'seg' mode:

<xsl:template match="seg">
  <xsl:apply-templates select="node()" mode="seg" />
</xsl:template>

and have separate templates for text nodes and elements:

<xsl:template match="*" mode="seg" />

<xsl:template match="text()" mode="seg">
  ...
</xsl:template>

To check the immediately preceding node, locate it with the
preceding-sibling:: axis:

  preceding-sibling::node()[1]

And test whether it's a ut element with the self:: axis:

  preceding-sibling::node()[1][self::ut]

Similarly, you can test whether the immediately following node is a ut
element with:

  following-sibling::node()[1][self::ut]

Having said that, I'm not sure whether this is going to help you do
what you need to do. In your example:

<tu>
  <tuv>
    <seg>Use <ut>{\cs6\f1\cf6\lang1024
</ut>&lt;b&gt;<ut>}</ut>Set<ut>{\cs6\f1\cf6\lang1024</ut>&lt;/b&gt;<ut>}
</ut> when you want to assign an object reference</seg>
  </tuv>
</tu>

There are three text nodes that are between ut elements:

  "&lt;b&gt;"
  "Set"
  "&lt;/b&gt;"

So what you'd actually get would be:

<tu>
  <tuv>
    <seg>Use (%TERM%)(%TERM%)(%TERM%) when you want to assign an object reference</seg>
  </tuv>
</tu>

I'm not sure what you should do about this because it's not clear to
me how you can tell that the "&lt;b&gt;" and "&lt;/b&gt;" text nodes
shouldn't be replaced...

Cheers,

Jeni

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


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


Current Thread