无法使用unparsed-text()读取xslt中的.properties文件

时间:2019-06-11 07:07:18

标签: xslt saxon

当我尝试将err.properties文件读入vText时

<xsl:variable name="errorMessages">
    <xsl:variable name="vText"
        select="unparsed-text('./err.properties','UTF-8')" />
    <ixbrlErrors>

        <xsl:analyze-string select="$vText"
            regex="(ix\d\d)\s?=\s?(.+)\n?">
            <xsl:matching-substring>
                <xsl:element name="{regex-group(1)}">
                    <xsl:value-of select="normalize-space(regex-group(2))"></xsl:value-of>
                </xsl:element>
            </xsl:matching-substring>
        </xsl:analyze-string>
    </ixbrlErrors>

</xsl:variable>

撒克逊人给了我以下错误。

Error on line 42 of validateIXBRLXslt.xsl:
  XTDE1200: Failed to read input file
  file:/D:/OIM_JSON_WS/BUSHCHAT_TRUNK_CERTIFIED/bushchat/target/classes/IXBRL/err.properties
  (java.nio.charset.MalformedInputException): Input length = 1
  in variable errorMessages 
  at xsl:call-template name="AllStartsFromHere" (file:/D:/OIM_JSON_WS/BUSHCHAT_TRUNK_CERTIFIED/bushchat/target/classes/IXBRL/validateIXBRLXslt.xsl#57)
Transformation failed: Run-time errors were reported

第42行是regex =“(ix \ d \ d)\ s?= \ s?(。+)\ n?”>

我尝试使用utf-8编码保存err.properties,但是没有效果。

1 个答案:

答案 0 :(得分:0)

我假设您在.properties文件中输入以下内容:

this is 254125
this is 9856524
ix25 = 20111
iax25 = 20222
ix25 = 20333
ibx25 = 20444

在XSLT 1.0中,根据我的理解,我尝试实现输出:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:dp="http://www.datapower.com/extensions" xmlns="http://www.datapower.com/extensions"
    xmlns:dpconfig="http://www.datapower.com/param/config" extension-element-prefixes="dp"
    exclude-result-prefixes="dp dpconfig">

    <xsl:output omit-xml-declaration="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="/">
        <xsl:variable name="errorMessages" select="unparsed-text('err.properties','UTF-8')"/>
            <xsl:analyze-string select="$errorMessages" regex="(ix\d\d)\s*=\s*(.*)">
                <xsl:matching-substring>
                    <xsl:value-of select="concat('&lt;',regex-group(1),'&gt;', regex-group(2), '&lt;/',regex-group(1),'&gt;', '&#x000A;')" disable-output-escaping="yes"/>
                </xsl:matching-substring>
            </xsl:analyze-string>
    </xsl:template>

</xsl:stylesheet>

我得到的输出如下:

<ix25>20111</ix25>
<ix25>20333</ix25>