xsl-list
[Top] [All Lists]

RE: [xsl] How can I test the last preceding text character?

2007-10-29 16:36:16

I'll leave someone else to answer the question about oXygen.

However, with this sort of mixed content it seems surprising that you want
to strip whitespace. Usually with mixed content whitespace text nodes are
significant.

You can of course skip whitespace text nodes in your query:

//e/preceding::node()[normalize-space()][1][ends-with(.,'x')]

Michael Kay
http://www.saxonica.com/

 

-----Original Message-----
From: Sascha Mantscheff [mailto:922492(_at_)gmx(_dot_)de] 
Sent: 29 October 2007 22:57
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] How can I test the last preceding text character?

Thank you. Additional question:

-- Example --------------------------
<text xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
version="2.0"> x <a>
    This is parent text a not ending with an x.
    <d>This ends with an x</d>
        <e>This should issue a message.</e>
    This is parent text ending with an x </a> </text>
-- /Example --------------------------

What irritates me is that in Oxygen the XPath
  //e/preceding::node()[1]
highlights the blank space before <e>, while
  //e/preceding::node()[2]
highlights the d element. But when I run Saxon on the example 
with the the test 
      <xsl:if test="ends-with(preceding::node()[1],'x')">
it fires a the e element and refers to the d element, not to 
the blank space.

Obviously, this is due to the 
    <xsl:strip-space elements="*"/>
directive in the XSL sheet. Can the XPath query control in 
the Oxygen IDE be configured to behave likewise?

Thanks again for your fast response.
s.m.



    This is parent text a not ending with an x.
    <d>This ends with an x</d>
    <e>This should issue a message.</e>
    This is parent text ending with an x </a>




Am Montag, den 29.10.2007, 21:37 +0000 schrieb Michael Kay:
Replace

preceding-sibling::*[1]/text()[last()]

with

preceding-sibling::node()[1]

If the preceding sibling is an element node, you'll get its string 
value automatically, you don't need to get it's text node 
children explicitly.

There's also an ends-with() function in 2.0 which might be clearer 
than regular expressions for such a simple job.

Michael Kay
http://www.saxonica.com/

-----Original Message-----
From: Sascha Mantscheff [mailto:922492(_at_)gmx(_dot_)de]
Sent: 29 October 2007 21:28
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] How can I test the last preceding text character?

How do I test if the very last character of any preceding 
text - be 
it in a parent or a sibling - has a certain value?
Example:

<a>
    This is parent text a not ending with an x.
    <d>This ends with an x</d>
    <e>This should issue a message.</e>
    This is parent text ending with an x </a>

Now I want to know for each child element is if it is 
preceded by an 
"x".
I can check the sibling with

<xsl:if 
test="matches(preceding-sibling::*[1]/text()[last()],'x\$') ">
    <xsl:message>
        Element <xsl:value-of select="name()"/> is 
preceded by an x.
    </xsl:message>
</xsl:if>

But I cannot test the surrounding parent content with the 
same model 
because the parent text may surround the child text.

What's the way to do it?





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




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


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



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