XSLT - 属性の作成 (xsl:attribute)

Advertisement

書式

<xsl:processing-instruction name="処理命令名">
    値
</xsl:processing-instruction>

<xsl:processing-instruction name="xsl-stylesheet">
    type="text/xsl" href="sample.xsl"
</xsl:processing-instruction>
<?xml-stylesheet type="text/xsl" href="sample.xsl"?> という処理命令が作成される。

サンプルコード

sample.xml
<?xml version="1.0" encoding="Shift_JIS"?>
<?xml-stylesheet type="text/xsl" href="./style.xsl"?>

<document>
    <book id="10">
        <title>AAA</title>
        <price>4000</price>
    </book>
    <book id="20">
        <title>BBB</title>
        <price>1000</price>
    </book>
    <book id="30">
        <title>CCC</title>
        <price>2000</price>
    </book>
    <book id="40">
        <title>DDD</title>
        <price>1500</price>
    </book>
    <book id="50">
        <title>EEE</title>
        <price>500</price>
    </book>
</document>
style.xsl
<?xml version="1.0" encoding="Shift_JIS"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="document">
    <xsl:processing-instruction name="xsl-stylesheet">
        type="text/xsl" href="sample.xsl"
    </xsl:processing-instruction>

    <xsl:apply-templates select="."/>
</xsl:template>

<xsl:template match="document">
    <bookshelf>
        <xsl:apply-templates select="book"/>
    </bookshelf>
</xsl:template>

<xsl:template match="book">
    <name><xsl:value-of select="title"/></name><br/>
</xsl:template>

</xsl:stylesheet>
生成されるコード
<?xml-stylesheet type="text/xsl" href="sample.xsl"?>

<bookshelf>
    <>name<>AAA<>/name<>
    <>name<>BBB<>/name<>
    <>name<>CCC<>/name<>
    <>name<>DDD<>/name<>
    <>name<>EEE<>/name<>
</bookshelf>

Advertisement

ショートカット

634トップページ
このカテゴリのトップページに戻る
634ラボ

サイト検索

Google

Web サイト内

Y!ログール