A
Arndt Jonasson
I have this xslt transform ex.xsl and an instance document ex.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xslutput method="text"/>
<xsl:template match="//*[contains(.,'fo') and string-length(.) > 3
and string-length(.) < 15]">
node=<xsl:value-of select="local-name()"/>
match=(<xsl:value-of select="."/>)
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="*">
</xsl:template>
</xsl:stylesheet>
<top>
<x>fo
o</x>
<y>bar</y>
</top>
When I run the command
$ xsltproc ex.xsl ex.xml
I get the following output:
node=top
match=(
fo
o
bar
)
node=x
match=(fo
o)
fo
o
That ought to be expected. What I cannot understand is that if I
change the tests that narrow down the length of the text, either
changing 3 to 4, or 15 to 14, nothing matches. What is the expected
length? Is it 4? What I originally tried to do was to find a call to
contains(., xxx) that would include the line break, and match, but I
failed to do that, and found this anomaly instead, which leads me to
suspect that the behaviour of xsltproc for string with line breaks in
them is not quite reliable.
Should I be able to match the text of the x element with the
expression
match="//*[contains(.,'fo
o') ]"
? Is there some other way to include a newline in the expression?
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xslutput method="text"/>
<xsl:template match="//*[contains(.,'fo') and string-length(.) > 3
and string-length(.) < 15]">
node=<xsl:value-of select="local-name()"/>
match=(<xsl:value-of select="."/>)
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="*">
</xsl:template>
</xsl:stylesheet>
<top>
<x>fo
o</x>
<y>bar</y>
</top>
When I run the command
$ xsltproc ex.xsl ex.xml
I get the following output:
node=top
match=(
fo
o
bar
)
node=x
match=(fo
o)
fo
o
That ought to be expected. What I cannot understand is that if I
change the tests that narrow down the length of the text, either
changing 3 to 4, or 15 to 14, nothing matches. What is the expected
length? Is it 4? What I originally tried to do was to find a call to
contains(., xxx) that would include the line break, and match, but I
failed to do that, and found this anomaly instead, which leads me to
suspect that the behaviour of xsltproc for string with line breaks in
them is not quite reliable.
Should I be able to match the text of the x element with the
expression
match="//*[contains(.,'fo
o') ]"
? Is there some other way to include a newline in the expression?