我想在XSLT 1.0中使用java字符串函數。具體來說就是java String替換函數。在xslt中使用java字符串函數
但它失敗,出現空指針異常。下面是我的嘗試:
1)--Declare namespace and call the java String class
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:jString="http://www.oracle.com/XSL/Transform/java/java.lang.String">
2)--Created a template to search for tag inputs that have an ampersand:
<xsl:template name="string-replace-all">
<xsl:param name="text" />
<xsl:choose>
<xsl:when test="contains($text, '&')">
<xsl:variable name="str1" select="jString:new($text)"/>
<xsl:value-of select="jString:replace($str1,'&','&')" />
<xsl:otherwise>
<xsl:value-of select="$text" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
3)--Call the template in the specific tags
<Nm>
<xsl:variable name="suppNm">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="Payee/Name" />
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$suppNm" />
</Nm>
不過,我不斷收到一個空指針異常: 引起:oracle.xdo.parser.v2.XPathException:擴展功能錯誤:錯誤調用「取代」:'java.lang中。 NullPointerException'
任何人都可以指導我如何使這項工作?
感謝
的可能的複製[?什麼是空指針異常,以及如何解決呢(https://開頭計算器.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Ivan
'&'本身不是合法的XML。我很驚訝你的XSLT被加載了。 – VGR
從XSLT到Java的調用完全取決於您使用的是哪個XSLT處理器。我從錯誤信息中懷疑這是Oracle處理器,但您需要告訴我們。爲什麼不切換到XPath本地提供基於正則表達式的字符串替換的XSLT 2.0/3.0? –