Skip to content

SB 3.2 - Nested Jar Support Breaks Nested XML Stylesheets #38581

Closed as not planned
@nmesot

Description

@nmesot

We have nested xml stylesheets that get read by the native Java XML parser / transformer.

<!-- stylesheets/subfolder/stylesheet.xsl -->
<axsl:stylesheet xmlns:axsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <axsl:variable name="generalCodes" select="document('GeneralCodeLists.xsd')"/>
    ...
/>
import org.w3c.Document;
import javax.xml.*;

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
Document sourceDoc = dbf.newDocumentBuilder.newDocument();
Document resultDoc = dbf.newDocumentBuilder.newDocument();

TransformerFactory factory = TransformerFactory.newInstance();
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "file");
StreamSource source = new StreamSource((new ClassPathResource("stylesheets/subfolder/stylesheet.xsl")).getInputStream());
Templates templates = factory.newTemplates(source);
Transformer transformer = templates.newTransformer();

transformer.transform(new DOMSource(sourceDoc), new DOMResult(resultDoc));

This throws the following exception

java.lang.Exception: Could not read stylesheet target 'GeneralCodeLists.xsd' because 'nested' access is not allowed due to restriction set by the accessExternalStylesheet property.

Setting the loaderImplementation to CLASSIC fixes the problem.

<build>
  <plugins>
    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>repackage</goal>
            </goals>
            <configuration>
              <loaderImplementation>CLASSIC</loaderImplementation>
            </configuration>
          </execution>
        </executions>
    </plugin>
  </plugins>
</build>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions