[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Michael here is the function but it has worked perfectly(or as perfectly as can be) in other instances.
<xsl:function name="f:f_StringEndsWith" as="xs:string">
<!-- get the last character -->
<xsl:variable name="l_LastCharacter" select="substring($p_String, string-length($p_String), 1)" />
<!-- get the last two characters -->
<xsl:variable name="l_LastTwoCharacter" select="substring($p_String, string-length($p_String) - 1, 2)" />
<!-- . : ! ? -->
<xsl:variable name="l_LastCharacterIs" select="if (matches($l_LastCharacter, '[.]|[:]|[!]|[?]')) then 'punct' else 'noPunct'" />
<!-- ." !" ?" .) !) ?) -->
<!--xsl:variable name="l_LastTwoCharacterAre" select="if (matches($l_LastTwoCharacter, '[."]|[!"]|[?"]|[.)]|[!)]|[?)]')) then 'punct' else 'noPunct'" /-->
<!-- the above failed in a couple of instances and so the var and choose below works. it is in longhand for ease of maintaining -->
<!-- ." !" ?" .) !) ?) -->
<xsl:variable name="l_LastTwoCharacterAre">
<xsl:choose>
<xsl:when test="$l_LastTwoCharacter = '."'"><xsl:value-of select="'punct'" /></xsl:when>
<xsl:when test="$l_LastTwoCharacter = '!"'"><xsl:value-of select="'punct'" /></xsl:when>
<xsl:when test="$l_LastTwoCharacter = '?"'"><xsl:value-of select="'punct'" /></xsl:when>
<xsl:when test="$l_LastTwoCharacter = '.)'"><xsl:value-of select="'punct'" /></xsl:when>
<xsl:when test="$l_LastTwoCharacter = '!)'"><xsl:value-of select="'punct'" /></xsl:when>
<xsl:when test="$l_LastTwoCharacter = '?)'"><xsl:value-of select="'punct'" /></xsl:when>
<xsl:otherwise><xsl:value-of select="'noPunct'" /></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="($l_LastCharacterIs = 'punct') or ($l_LastTwoCharacterAre = 'punct')"><xsl:value-of select="'punct'" /></xsl:when>
<xsl:otherwise><xsl:value-of select="'noPunct'" /></xsl:otherwise>
</xsl:choose>
</xsl:function>
I'll add a test for an empty string and will test if any data is present.
Thanks
Mario
Michael Kay wrote:
Re: [xsl] Trying to find following sibling that ends in punctuation
Subject: Re: [xsl] Trying to find following sibling that ends in punctuation From: "Marijan (Mario) Madunic" <hajduk@xxxxxxxx> Date: Sat, 04 Nov 2006 08:54:23 -0800 |
Michael here is the function but it has worked perfectly(or as perfectly as can be) in other instances.
<xsl:function name="f:f_StringEndsWith" as="xs:string">
<!-- p_String to test --> <xsl:param name="p_String" />
<!-- get the last character -->
<xsl:variable name="l_LastCharacter" select="substring($p_String, string-length($p_String), 1)" />
<!-- get the last two characters -->
<xsl:variable name="l_LastTwoCharacter" select="substring($p_String, string-length($p_String) - 1, 2)" />
<!-- . : ! ? -->
<xsl:variable name="l_LastCharacterIs" select="if (matches($l_LastCharacter, '[.]|[:]|[!]|[?]')) then 'punct' else 'noPunct'" />
<!-- ." !" ?" .) !) ?) -->
<!--xsl:variable name="l_LastTwoCharacterAre" select="if (matches($l_LastTwoCharacter, '[."]|[!"]|[?"]|[.)]|[!)]|[?)]')) then 'punct' else 'noPunct'" /-->
<!-- the above failed in a couple of instances and so the var and choose below works. it is in longhand for ease of maintaining -->
<!-- ." !" ?" .) !) ?) -->
<xsl:variable name="l_LastTwoCharacterAre">
<xsl:choose>
<xsl:when test="$l_LastTwoCharacter = '."'"><xsl:value-of select="'punct'" /></xsl:when>
<xsl:when test="$l_LastTwoCharacter = '!"'"><xsl:value-of select="'punct'" /></xsl:when>
<xsl:when test="$l_LastTwoCharacter = '?"'"><xsl:value-of select="'punct'" /></xsl:when>
<xsl:when test="$l_LastTwoCharacter = '.)'"><xsl:value-of select="'punct'" /></xsl:when>
<xsl:when test="$l_LastTwoCharacter = '!)'"><xsl:value-of select="'punct'" /></xsl:when>
<xsl:when test="$l_LastTwoCharacter = '?)'"><xsl:value-of select="'punct'" /></xsl:when>
<xsl:otherwise><xsl:value-of select="'noPunct'" /></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="($l_LastCharacterIs = 'punct') or ($l_LastTwoCharacterAre = 'punct')"><xsl:value-of select="'punct'" /></xsl:when>
<xsl:otherwise><xsl:value-of select="'noPunct'" /></xsl:otherwise>
</xsl:choose>
</xsl:function>
I'll add a test for an empty string and will test if any data is present.
Thanks
Mario
Michael Kay wrote:
You haven't shown the function
f:f_StringEndsWith($p_Node)
You would get infinite recursion if this function always returns the value "noPunct" when its argument is an empty sequence.
Just a theory.
Michael Kay
http://www.saxonica.com/
-----Original Message-----
From: Marijan (Mario) Madunic [mailto:hajduk@xxxxxxxx] Sent: 04 November 2006 00:44
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Trying to find following sibling that ends in punctuation
Using XSLT 2, XPath 2, and Saxon8
I'm trying to get the count(of preceding::*) of a following sibling node that ends with some sort of punctuation, and throw this value into a variable.
I've created a recurisive template
<xsl:template name="ct_PositionOfNodeThatEndsWithPunct">
<!-- set a default value for p_Node -->
<xsl:param name="p_Node" select="following-sibling::*[self::P][1]" />
<!-- test what the element ends with --> <xsl:variable name="l_EndsWith" select="f:f_StringEndsWith($p_Node)" />
<xsl:choose>
<xsl:when test="$l_EndsWith = 'noPunct'">
<xsl:call-template
name="ct_PositionOfNodeThatEndsWithPunct">
<xsl:with-param name="p_Node" select="following-sibling::*[self::P][1]" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise><xsl:value-of select="count(preceding::*) + 1" /></xsl:otherwise>
</xsl:choose>
</xsl:template>
Now I was hoping that because called templates are context sensitive I can keep on just doing "select="following-sibling::*[self::P][1]" as I've done to give p_Node a new value to iterate through. I keep on getting out of memory error. Memory is not an issue as from my past experiences when I get this error when I introduce a recursive template usually means I've given the recursion no way out. But I can't see why this is happening.
Any insight will be greatly appreciated.
Thanks
Mario
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Trying to find following , Michael Kay | Thread | RE: [xsl] Trying to find following , Michael Kay |
RE: [xsl] REsending: make element r, Philip Vallone | Date | RE: [xsl] Encoding issues with docu, Michael Kay |
Month |