Reputation: 2582
I try to localize XSLT templates in web application and I want to use entities mechanism for this. But values does not substituted in result document.
Ruby script
require 'nokogiri'
doc = Nokogiri::XML(File.read('test.xml'))
xslt = Nokogiri::XSLT(File.read('test.xsl'))
puts xslt.transform(doc)
XML document
<?xml version="1.0" encoding="UTF-8" ?>
<CommonCard>
<Test/>
</CommonCard>
XSLT stylesheet
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY labelHello "hello world!">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="utf-8" method="xml" />
<xsl:template match="/">
&labelHello; 123
</xsl:template>
</xsl:stylesheet>
I want to get this
<?xml version="1.0" encoding="utf-8"?>
hello world! 123
But now I get this
<?xml version="1.0" encoding="utf-8"?>
123
What am I doing wrong?
UPD
I use Nokogiri XML engine
Upvotes: 1
Views: 488
Reputation: 12729
I suspect that this is just a limitation of Nokogiri. I suggest a work-around: use variables instead of entities, like so ...
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="labelHello" select="'hello world!'" />
<xsl:template match="/">
<xsl:value-of select="$labelHello" /> 123
</xsl:template>
</xsl:stylesheet>
Upvotes: 1