Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get the unparsed entity attribute's value from XSLT?
    text
    copied!<p>I have a problem with XSLT and unparsed entity in XML. Here is a fictional scenario. First I got an XML file named doc.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt; &lt;!DOCTYPE document [ &lt;!ELEMENT document (employee)*&gt; &lt;!ELEMENT employee (lastname, firstname)&gt; &lt;!ELEMENT lastname (#PCDATA)&gt; &lt;!ELEMENT firstname (#PCDATA)&gt; &lt;!NOTATION FOO SYSTEM 'text/xml'&gt; &lt;!ENTITY ATTACHMENT SYSTEM 'attach.xml' NDATA FOO&gt; &lt;!ATTLIST employee detail ENTITY #IMPLIED&gt; ]&gt; &lt;document&gt; &lt;employee detail="ATTACHMENT"&gt; &lt;lastname&gt;Bob&lt;/lastname&gt; &lt;firstname&gt;Kevin&lt;/firstname&gt; &lt;/employee&gt; &lt;/document&gt; </code></pre> <p>In this XML file, I use an unparsed entity(NDATA) for the attribute "detail" of the element "employee". The attach.xml is:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;name&gt;Bob Kevin&lt;/name&gt; </code></pre> <p>Then i want to use XSLT to generate an output together with the attach.xml embedded. My XSLT file is named doc.xsl:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt; &lt;xsl:output method="xml" indent="yes"/&gt; &lt;xsl:template match="document"&gt; &lt;Document&gt; &lt;xsl:apply-templates select="employee"/&gt; &lt;/Document&gt; &lt;/xsl:template&gt; &lt;xsl:template match="employee"&gt; Employee is: &lt;xsl:value-of select="@detail"/&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>Finally, I run using Xalan 2.7.1 :</p> <pre><code>java -jar xalan.jar -IN doc.xml -XSL doc.xsl -OUT docout.xml </code></pre> <p>The output is:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;Document&gt; Employee is: ATTACHMENT &lt;/Document&gt; </code></pre> <p>This is not what i want. I want the output looks like this:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;Document&gt; Employee is: &lt;name&gt;Bob Kevin&lt;/name&gt; &lt;/Document&gt; </code></pre> <p>How should I rewrite the XSLT script to get the correct result? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload