-2

I got this error when I do this in Java :

InputStream foo = getClass().getResourceAsStream(XML_TRANSFORM);
javax.xml.transform.Transformer transformer = factory.newTransformer(new StreamSource(foo)); // error

I can not figure out where the error is, because I have no more information and because XML online validators tell me that there is no syntax error (ex : https://www.w3schools.com/xml/xml_validator.asp)

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

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <TimeSeriesDoc>
        <xsl:apply-templates select="/eai-document" />
        <xsl:apply-templates select="eai-timeserie" />
    </TimeSeriesDoc>

    <xsl:template match="/eai-document">
        <DocumentHeader>
            <Identification v="{@identification}" />
            <Version v="{@version}" />
            <Type v="{@type}" />
            <Status v="{@status}" />
            <ClassificationType v="{@classification}" />
            <CreationDateTime v="{@creation-date-time}" />
            <ProcessType v="{@process-type}" />
            <Initiator v="{@initiator}" />
            <InitiatorRole v="initiator-role}" />
            <Receptor v="{@receptor}" />
            <ReceptorRole v="{@receptor-role}" />
            <ElaborateDateTime v="{@elaborate-date-time}" />
        </DocumentHeader>
    </xsl:template>

    <xsl:template match="eai-timeserie">
        <TimeSeries>
            <Identification v="{@identification}" />
            <BusinessType v="{@business-type}" />
            <Product v="{@product}" />
            <ObjectAggregation v="{@object-agregation}" />
            <AreaIdentification v="{@area-id}" />
            <ResourceObject v="{@resource-object}" />
            <MeasureUnit v="{@measure-unit}" />
            <CurveType v="{@curve-type}" />

            <xsl:apply-templates select="eai-period" />
        </TimeSeries>
    </xsl:template>

    <xsl:template match="eai-period">
        <Period>
            <Resolution v="{@resolution}" />

            <xsl:apply-templates select="eai-point" />
        </Period>
    </xsl:template>

    <xsl:template match="eai-point">
        <Pt>
            <P v="{@position}" />
            <Q v="{@quantity}" />
        </Pt>
    </xsl:template>

</xsl:stylesheet>
Flyout91
  • 782
  • 10
  • 31
  • 1
    See https://stackoverflow.com/questions/20605328/official-xslt-validator for why that validator is not helping you. Using a tool such as `xsltproc` immediately identifies a number of specific problems with your stylesheet. – Joe Nov 22 '17 at 11:20
  • 1
    Your document is valid XML, but not valid XSLT. Getting a 'green light' from an XML validator is pointless, since you are feeding the document to an XSLT processor. The exception thrown when invoking newTransformer tells you exactly what the error (what kind of syntax violation) is and where to find it (line number). – jarnbjo Nov 22 '17 at 11:21
  • - Joe - Oh okay thank you. - jarnbjo - No it absolutely does not tell me where the error is and where to find it. Otherwise I wouldn't be here. - Meyer Cohen - it is a duplicate indeed, thank you (couldn't find anything useful when I searched before posting). Turns out my inputstream is null, even if I have no idea why...really the method should throw a IllegalArgumentException... – Flyout91 Nov 22 '17 at 11:43

1 Answers1

1

There's a slightly odd rule in XSLT which means that if you had

<x:TimeSeriesDoc>
    <xsl:apply-templates select="/eai-document" />
    <xsl:apply-templates select="eai-timeserie" />
</x:TimeSeriesDoc>

at the top level of your stylesheet then it would be valid (but ignored and useless), while if you have

<TimeSeriesDoc>
    <xsl:apply-templates select="/eai-document" />
    <xsl:apply-templates select="eai-timeserie" />
</TimeSeriesDoc>

then it is invalid (and an error).

If the processor doesn't tell you where the error is then that's probably because your Java application is sending the system error output stream to somewhere where you aren't seeing it. Either fix this problem in your application, or try debugging your stylesheets using an environment such as oXygen before you compile them from a Java application. Since your error suggests a lack of familiarity with the basics of the XSLT language, you would really benefit from using a tool such as oXygen (or Stylus Studio or XML Spy) for development.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • Thank you for your response. In fact the only information I had was **ERROR : 'null'**. Turned out that my InputStream object was null, because my path to the xsl was wrong. When my InputStream was right, I didn't had an error for what you said. Simply the transformation produced a document without the tag. – Flyout91 Nov 24 '17 at 15:10