I'm trying to use the <xsl:attribute-set>
in my xsl document but I keep getting error messages:
- compilation error: line 47 element attribute-set
- element attribute-set only allowed as child of stylesheet
I've also checked the W3Schools website's explanation on XSLT attribute-sets and found out that:
Must be child of <xsl:stylesheet> or <xsl:transform>.
I don't understand what this means, can anyone explain?
If you need more information about my documents, WAMP server set up please comment below.
The first two lines of my XSL document is:
<?xml version="1.0" encoding="UTF-8"?>
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
I have no idea what they do, just that without it, my XSL will not work.
I am basically transforming my XML into HTML using this XSL file. The whole process is done by PHP:
# START XSLT
$xslt = new XSLTProcessor();
$XSL = new DOMDocument();
$XSL->load('hello.xsl');
$xslt->importStylesheet($XSL);
# LOAD XML FILE
$XML = new DOMDocument();
$XML->load('hello.xml');
#PRINT
print $xslt->transformToXML($XML);
You are using the very rarely-seen "literal result element as stylesheet" facility, also known as a "simplified stylesheet", in which the
xsl:stylesheet
element and the outermostxsl:template
are implicit. Your problem illustrates why this facility is so rarely used - it quickly runs out of steam. Because there is noxsl:stylesheet
element, none of the usual children ofxsl:stylesheet
can be present, and this includes declarations of attribute sets.Change your code to wrap it in an explicit
xsl:stylesheet
andxsl:template match="/"
. Then add anxsl:attribute-set
at the same level as thexsl:template
.