1

I have XML files that use embedded entity declarations. In the result file I need to replace the entity names with the actual file they are pointing to. But AFAIK entities cannot be pointed to in an XSLT stylesheet, as they are supposed to be handled by the XML parser.

Sample source file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic SYSTEM "../../../App/Converted-DTD.dtd" [

<!-- Begin Document Specific Declarations -->
<!NOTATION pdf SYSTEM "">
<!ENTITY image1 SYSTEM "graphics/img-1.svg" NDATA pdf>
<!ENTITY image2 SYSTEM "graphics/img-2.svg" NDATA pdf>
<!-- End Document Specific Declarations -->

]>

<topic>
    <title>My test topic</title>
        <body>
            <p>This is an image:
            <image entity="image1"/></p>
            <p>This is another image
            <image entity="image2"/></p>        
        </body>
</topic>

What I need is a file that changes the entity reference to an actual href:

<topic>
    <title>My test topic</title>
        <body>
            <p>This is an image:
            <image href="graphics/img-1.svg"/></p>
            <p>This is another image
            <image href="graphics/img-2.svg"/></p>        
        </body>
</topic>

I cannot rely on the entities being declared in a DTD as every file has different entities pointing to different files.

Maybe it is trivial but I could not find a way to get to the embedded document specific declarations.

4everJang
  • 321
  • 2
  • 12
  • https://www.w3.org/TR/xslt-30/#func-unparsed-entity-uri might help but all DTD related stuff depends on parser, XSLT processor and these days also security restrictions cooperating to make them available. – Martin Honnen Jun 25 '20 at 13:30
  • Note that these are *unparsed* entities, which are a rare breed. Most of the stuff you'll find on the internet about XSLT and entities is referring to *parsed* entities. – Michael Kay Jun 25 '20 at 16:22

1 Answers1

0

You can try

  <xsl:template match="image/@entity">
      <xsl:attribute name="href" select="unparsed-entity-uri(.)"/>
  </xsl:template>
Martin Honnen
  • 160,499
  • 6
  • 90
  • 110