Search code examples
xsltentitylibxml2

xsltproc: Can I add breaks (or entities) to --stringparams?


I am trying to feed xsltproc a stringparam that contains a break... It does not seem to work. Minimal example below.

Input

This is bogus.xml:

<?xml version="1.0" encoding="UTF-8"?>
<this>
  <that/>
</this>

This is test.xsl:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:param name="somestring" select="'here is a&#10;break'"/>
  <xsl:template match="/">
    <xsl:message>|<xsl:value-of select="$somestring"/>|</xsl:message>
  </xsl:template>
</xsl:stylesheet>

And this is my command line: xsltproc --stringparam somestring 'another string with a&#10;break' test.xsl bogus.xml

Output

And the output looks like this:

|another string with a&#10;break|

The output I want is this:

|another string with a
break|

Solution

  • When using Bash this can be achieved like this:

    xsltproc --stringparam somestring $'another string with a\nbreak' test.xsl bogus.xml
    

    For more information about ansi-c quoting see here