XML > XSLT > 要素・属性などの生成
要素の生成
要素を生成する場合は
xsl:element
を使う。
(書式) <xsl:element name="要素名"> テンプレート </xsl:element> |
属性の生成
属性を生成する場合は
xsl:attribute
を使う。
(書式) <xsl:attribute name="属性名"> テンプレート </xsl:attribute> |
属性の一括定義
属性を一括で定義する場合は
xsl:attribute-set
を使う。
(書式) <xsl:attribute-set name="属性セット名"> 属性定義 </xsl:attribute> (例) <xsl:attribute-set name="position"> <xsl:attribute name="left">10</xsl:attribute> <xsl:attribute name="right">200</xsl:attribute> <xsl:attribute name="top">20</xsl:attribute> <xsl:attribute name="bottom">500</xsl:attribute> </xsl:attribute> <box xsl:use-attribute-set="position"> <xsl:attribute name="color">white</xsl:attribute> </xsl:box> <box xsl:use-attribute-set="position"> <xsl:attribute name="color">black</xsl:attribute> </xsl:box> 上記例は以下と同じ <box xsl:use-attribute-set="position"> <xsl:attribute name="color">white</xsl:attribute> <xsl:attribute name="left">10</xsl:attribute> <xsl:attribute name="right">200</xsl:attribute> <xsl:attribute name="top">20</xsl:attribute> <xsl:attribute name="bottom">500</xsl:attribute> </xsl:box> <box xsl:use-attribute-set="position"> <xsl:attribute name="color">black</xsl:attribute> <xsl:attribute name="left">10</xsl:attribute> <xsl:attribute name="right">200</xsl:attribute> <xsl:attribute name="top">20</xsl:attribute> <xsl:attribute name="bottom">500</xsl:attribute> </xsl:box> |
テキストノードの生成
テキストノードを生成する場合は
xsl:text
を使う。
(書式) <xsl:text disable-output-escaping={"yes" | "no"}> テキスト </xsl:text> disable-output-escaping 属性は省略可能(デフォルトは "no") |
通常、
xsl:text
属性は省略可能。しかし、テキストの中にエスケープさせずにそのままブラウザに解析させたい
文字列がある場合は省略せずに、
<xsl:text disable-output-escaping="yes"><a></xsl:text> |
コメントの生成
コメントを生成する場合は
xsl:comment
を使う。
(書式) <xsl:comment> コメント </xsl:comment> |
処理命令の生成
処理命令を生成する場合は
xsl:processing-instruction
を使う。
(書式) <xsl:processing-instruction name="処理命令ターゲット名"> 処理命令内容 </xsl:processing-instruction> |