Search code examples
xmlxsltxml-entities

Can I pass entity from xml data to xslt stylesheet?


I have a dozen of xslt templates and most of them using one specific entity ('ent' in my example). I'm not able to change these templates but I can change outputed xml data.

The question is - is it possible to pass entity declared in xml data to xslt stylesheets? I am trying to make it like this, but fail:

XML document

<!DOCTYPE xsl:stylesheet [<!ENTITY ent "World">]>

<?xml-stylesheet type='text/xsl' href='xslt.xslt'?>

<doc/>

XSL xslt.xslt

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

<xsl:template match="/">

<h1>Hello: &ent;</h1>

</xsl:template>

</xsl:stylesheet>


Solution

  • Well any entity referenced in the XSLT stylesheet needs to be declared in the stylesheet itself respectively in any external DTD the stylesheet references. Declaring an entity in the XML input does not help at all. So the answer is no, declaring entities in an XML document does not allow you to reference such entities in an XSLT stylesheet being used later on to transform the XML.