XML の CDATA コメントを HTML テキストとして出力する XSL コードの例

Y2J
リリース: 2017-04-25 16:43:50
オリジナル
2060 人が閲覧しました

DOM を使用して XML ファイルにアクセスするには、XML ファイルを HTML Web ページにリンクする必要があります。

サンプルコード

1. test.xml

<?xml version="1.0" encoding="gb2312"?>
<?xml-stylesheet href="test.xsl" type="text/xsl"?>
<entry>
<title>entry with images</title>
<date>August 09, 2003</date>
<author>Kevin</author>
<idnum>000033</idnum>
<permalink>http://alazanto.org/xml/archives/000033.xml</permalink>
<body xmlns:html="http://www.w3.org/1999/xhtml"><![CDATA[]]></more>
<comment-link>http://alazanto.org/xml/archives/000033_comments.xml</comment-link>
<comment-count>6</comment-count>
</entry>
ログイン後にコピー
ログイン後にコピー

2. test.xsl

<?xml version="1.0"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/entry"><html><head></head><body><xsl:value-of select="title" /><xsl:value-of select="body" disable-output-escaping="yes"/>
</body></html></xsl:template></xsl:stylesheet>
ログイン後にコピー
ログイン後にコピー


キーは使用される名前空間です xmlns:xsl="www.w3.org/1999/XSL/Transform" を追加しますdisable-output-escaping="yes" 出力時

サンプルコード

1. test.xml

<?xml version="1.0" encoding="gb2312"?>
<?xml-stylesheet href="test.xsl" type="text/xsl"?>
<entry>
<title>entry with images</title>
<date>August 09, 2003</date>
<author>Kevin</author>
<idnum>000033</idnum>
<permalink>http://alazanto.org/xml/archives/000033.xml</permalink>
<body xmlns:html="http://www.w3.org/1999/xhtml"><![CDATA[]]></more>
<comment-link>http://alazanto.org/xml/archives/000033_comments.xml</comment-link>
<comment-count>6</comment-count>
</entry>
ログイン後にコピー
ログイン後にコピー

2. test.xsl

<?xml version="1.0"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/entry"><html><head></head><body><xsl:value-of select="title" /><xsl:value-of select="body" disable-output-escaping="yes"/>
</body></html></xsl:template></xsl:stylesheet>
ログイン後にコピー
ログイン後にコピー

キーは使用する名前空間 xmlns:xsl="http://www. w3.org/1999/XSL/Transform" を指定し、出力時に disable-output-escaping="yes" を追加します

以上がXML の CDATA コメントを HTML テキストとして出力する XSL コードの例の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!