Shubham Asolkar
Shubham Asolkar

Reputation: 45

unable to read .properties file in xslt using unparsed-text()

When i try to read the err.properties file into 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>

saxon gives me the following error..

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

line 42 is regex="(ix\d\d)\s?=\s?(.+)\n?">

I tried saving err.properties with utf-8 encoding but there is no effect.

Upvotes: 0

Views: 475

Answers (1)

Amrendra Kumar
Amrendra Kumar

Reputation: 1816

I assume your Input in .properties file like:

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

here with the XSLT 1.0 i tried to achieve the output as i understand:

<?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>

Below output i got:

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

Upvotes: 1

Related Questions