xsl:value-of記述例

ソースXML文書

<?xml version="1.0" encoding="Shift_JIS" ?>
<book>
  <title code="1234">概説XML</title>
</book>

XSLTスタイルシート
<?xml version="1.0" encoding="Shift_JIS" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <answer>
      <!-- title要素のテキストを生成する -->
      <xsl:value-of select="book/title" />
      <!-- code属性のテキストを生成する -->
      <xsl:value-of select="book/title/@code" />
    </answer>
  </xsl:template>
</xsl:stylesheet>

結果XML文書
<?xml version="1.0" encoding="UTF-8"?>
<answer>概説XML1234</answer>

xsl:value-of要素で選択するノードが複数存在した場合、最初のノードの値をテキストとして生成する。次の例を示す。
ソースXML文書
<?xml version="1.0" encoding="Shift_JIS" ?>
<book>
  <title code="1234">概説XML</title>
  <title code="5678">XMLを学ぼう</title>
</book>

XSLTスタイルシート
<?xml version="1.0" encoding="Shift_JIS" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <answer>
      <xsl:value-of select="book/title" />
    </answer>
  </xsl:template>
</xsl:stylesheet>

結果XML文書
<?xml version="1.0" encoding="UTF-8"?>
<answer>概説XML</answer>
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License