0

私の英語でごめんなさい。

XMLサンプルを書きました:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="./test.xslt"?>
<document>
  <paragraph id="p1">
    I like &lt;i&gt;the flowers&lt;/i&gt;!!!
  </paragraph>
  <paragraph id="p2">
    <![CDATA[I like <i>the people</i>!!!]]>
  </paragraph>
</document>

そして、サンプル用の 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="html"/>
  <xsl:template match="/">
    <html>
      <body>
        <p>
          <xsl:value-of select="/document/paragraph[@id='p1']"/>
          <br/>
          <xsl:value-of select="/document/paragraph[@id='p2']"/>
        </p>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

テキスト値 (<i>一部のテキスト</i>) でフォーマットを指定しました。しかし、フォーマットは起こりません。ブラウザに次の結果が表示されます。

I like <i>the flowers</i>!!! 
I like <i>the people</i>!!!

指定されたフォーマットを強制的に適用する方法は?

よろしく

4

2 に答える 2

1

これはよくある質問です。

破棄されたマークアップ (エスケープされた文字列表現にシリアル化されたものなど) は、ブラウザーによってテキストとして表示されます。これは、エスケープされた文字が正確に解釈される方法です)。

目的のフォーマットを実現するために、マークアップを破棄しないでください。

それ以外の:

I like &lt;i&gt;the flowers&lt;/i&gt;!!!  

使用する:

I like <i>the flowers<i>!!! 

また、以下を置き換えます。

 <xsl:value-of select="/document/paragraph[@id='p1']"/>

と:

<xsl:copy-of select="/document/paragraph[@id='p1']/node()"/>    

要約する:

次の XML ドキュメントを使用します

<document>
    <paragraph id="p1">
      I like <i>the flowers</i>!!!
  </paragraph>
    <paragraph id="p2">I like <i>the people</i>!!!</paragraph>
</document>

変換を次のように変更します

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="html"/>
      <xsl:template match="/">
        <html>
          <body>
            <p>
              <xsl:copy-of select="/document/paragraph[@id='p1']/node()"/>
              <br/>
              <xsl:copy-of select="/document/paragraph[@id='p2']/node()"/>
            </p>
          </body>
        </html>
      </xsl:template>
</xsl:stylesheet>

これにより、必要な正しい結果が生成されます

<html>
   <body>
      <p>
              I like <i>the flowers</i>!!!
           <br>I like <i>the people</i>!!!
      </p>
   </body>
</html>

ブラウザに次のように表示されます

は花が好きです!!!
は人々が好きです!!!

于 2012-04-07T15:49:50.943 に答える
0

私は英語をよく理解しておらず、XSLでも理解しにくいため、上記のコメントにある議論を理解するのは困難です。私にとって「disable-output-escaping="yes"」を使用するオプションは、単純で便利なようです。'xsl:copy-of'のオプションも私にとって興味深いものであり、感謝しています。

于 2012-04-08T08:29:05.737 に答える