Using XPath function fn:replace from XSLT

前端 未结 2 1108
灰色年华
灰色年华 2021-01-05 08:34

I\'m trying to use XSLT to convert a simple XML schema to HTML and planned to use fn:replace to replace returns (\\n) with

;.

相关标签:
2条回答
  • 2021-01-05 09:12

    XPath 2.0 has a replace function that you can use with any XSLT 2.0 processor like Saxon 9 or AltovaXML tools or Gestalt. You seem to try to use the function with an XSLT 1.0 processor, that is not going to work. In case you are restricted to an XSLT 1.0 processor you will need to implement the replacement with a named recursive template or with the help of an extension.

    However note that even with XSLT 2.0 your attempt to use replace seems wrong as you will produce a text node with a 'p' tag markup while I assume you want to create a 'p' element node in the result. So even with XSLT 2.0 using analyze-string instead of replace is more likely to get you the result you want.

    0 讨论(0)
  • 2021-01-05 09:29

    By bumping the version attribute of <xsl:stylesheet> to 2.0 and using

    <xsl:value-of select="replace(description, '\n', '<p/>')" disable-output-escaping="yes" />

    I was able to make the replace work.

    0 讨论(0)
提交回复
热议问题