0

I'm parsing a text file using XSLT 1.0. I'm tokenizing on line breaks. Whenever I run into a '<' character the template stops and doesn't output anymore data.

The text file:

test1
test2 < test
test3

The template

<xsl:template match="/">
  <vce>
    <!-- tokenize on line endings -->
    <xsl:for-each select="str:tokenize(.,'&#10;')">
      <xsl:apply-templates select="." mode="new-document" />
    </xsl:for-each>
  </vce>
</xsl:template>

<xsl:template match="*" mode="new-document">
  <document>
    <content name="test">
      <xsl:value-of select="." />
    </content>
  </document>
</xsl:template>

The output:

<vce>
  <document>
    <content name="test">test1</content>
  </document>
  <document>
    <content name="test">test2 </content>
  </document>
</vce>

Expected output:

<vce>
  <document>
    <content name="test">test1</content>
  </document>
  <document>
    <content name="test">test2 < test</content>
  </document>
  <document>
    <content name="test">test3</content>
  </document>
</vce>

Does str:tokenize have problems with certain characters?

spyderman4g63
  • 4,087
  • 4
  • 22
  • 31
  • 3
    Consider to post minimal but complete details to allow us to reproduce the problem so tell us which XSLT processor you use, how you pass a text file to the XSLT 1.0 processor. – Martin Honnen Jul 11 '17 at 15:29
  • It's bundled into an application but I believe it's saxon parser. – spyderman4g63 Jul 11 '17 at 16:25
  • Your "expected output" is invalid XML: the `<` character is not allowed except 1) when marking the start of a tag, 2) when escaped as `<`, or 3) when contained in a `<![CDATA[...]]>` section. – Eiríkr Útlendi Jul 11 '17 at 16:29
  • 1
    Saxon is an XSLT processor, not an XML parser. It exists in several versions and editions but I am not sure it ever supported `str:tokenize` from EXSLT. Xalan Java does, as does libxslt, but your example "parsing a text file" is difficult to understand with XSLT 1.0 processors as they take XML input. – Martin Honnen Jul 11 '17 at 16:30
  • 1
    @spyderman4g63 **1.** See how to identify your processor here: https://stackoverflow.com/questions/25244370/how-can-i-check-which-xslt-processor-is-being-used-in-solr/25245033#25245033 **2.** Try to provide us with a reproducible example; the whole thing is a mystery now, because AFAIK there is no way to process a text file using XSLT 1.0. – michael.hor257k Jul 11 '17 at 16:39
  • I believe the problem is with the data being passed to the xslt templates and not with the function itself. – spyderman4g63 Jul 11 '17 at 19:06

0 Answers0