電子書籍の厳選無料作品が豊富!

次のようなXMLファイルをXSLTで処理したいのですが、&baseの部分がうまく表示できません。
どのようにしたら表示できるでしょうか?

■a.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="a.xsl"?>
<!DOCTYPE test [
<!ELEMENT name (#PCDATA)>
<!ENTITY base SYSTEM "base.xml">
]>
<test>
<name>abc</name>
&base;
</test>

■base.xml
<?xml version="1.0" encoding="UTF-8"?>
<base>base</base>

■a.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" />

<xsl:template match="/">
<xsl:apply-templates select="test" />
<xsl:apply-templates select="base" />
</xsl:template>

<xsl:template match="test">
name:<xsl:value-of select="name" />
</xsl:template>

<xsl:template match="base">
base:<xsl:value-of select="base" />
</xsl:template>

</xsl:stylesheet>

□結果
name:abc
※base.xmlの内容を表示できない

A 回答 (1件)

いくつか考えられますが、


まずbase.xmlのxml構造としてルート(base)しかないのが気になります。それと
<xsl:template match="base">
base:<xsl:value-of select="base" />
</xsl:template>
ではなく、
<xsl:template match="base">
base:<xsl:value-of select="." />
</xsl:template>
です。
自分のノードにいる場合、
自分を表示するには、「.」を使用します。
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!