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